In R, remove all dots from string apart from the last

Viewed 9264

I have a list of strings like this:

mystr <- c("16.142.8",          
       "52.135.1",         
       "40.114.4",          
       "83.068.8",         
       "83.456.3",         
       "55.181.5",         
       "76.870.2",         
       "96.910.2",         
       "17.171.9",         
       "49.617.4",         
       "38.176.1",         
       "50.717.7",         
       "19.919.6")

I know that the first dot . is just a thousands separator, while the second one is the decimal operator.

I want to convert the strings to numbers, so the first one should become 16142.8, the second 52135.1, and so on.

I suspect that it migh be done with regular expressions, but I'm not sure how. Any ideas?

2 Answers
Related