I have a csv file, where the prices after exported in R as a list, are worded like: $115.00 USD, so I cannot convert it with
as.numeric(sub('\\$','',as.character(Data)))
because it returns with N/As because of the " USD" part.
I have a csv file, where the prices after exported in R as a list, are worded like: $115.00 USD, so I cannot convert it with
as.numeric(sub('\\$','',as.character(Data)))
because it returns with N/As because of the " USD" part.
It's easiest to just remove everything that isn't a number or period:
> gsub("[^0-9.]", "", "$115.00 USD")
[1] "115.00"
If you want to ensure that you have a contiguous string of characters from the input, you can use a capture:
> sub("[^0-9.]*([0-9.]*).*", "\\1", "$115.00 USD")
[1] "115.00"