I'm new to R and have a fairly simple question. I am working with a data frame and want to convert one of the columns from a character to numeric. The issue I am running into is that it represents a price and is currently formatted as $7 for 7 dollars. I want to make this 7. When i use as.numeric
it returns all NA
s. I also tried gsub("$","", cookies$Price)
, but the $
isn't dropping off.
Asked
Active
Viewed 60 times
0
-
5`$` is a special regex character, you need to escape it as `\\$` – hrbrmstr Oct 16 '15 at 13:55
-
2That and use `fixed=TRUE` if you do not want any meta-characters applied. – Pierre L Oct 16 '15 at 13:57
-
As @Hrbrmstr said; `gsub("\\$","", cookies$Price)` would do the trick for your code – Bas Oct 16 '15 at 13:57
-
1Or `gsub("[$]", "", cookies$Price)` – talat Oct 16 '15 at 14:00
-
Thanks for the help. This worked. I appreciate it. – JB17 Oct 17 '15 at 20:13