Related question here.
So I have a character vector with currency values that contain both dollar signs and commas. However, I want to try and remove both the commas and dollar signs in the same step.
This removes dollar signs =
d = c("$0.00", "$10,598.90", "$13,082.47")
gsub('\\$', '', d)
This removes commas =
library(stringr)
str_replace_all(c("10,0","tat,y"), fixed(c(","), "")
I'm wondering if I could remove both characters in one step.
I realize that I could just save the gsub results into a new variable, and then reapply that (or another function) on that variable. But I guess I'm wondering about a single step to do both.
take a look at ?regexp
for additional special regex notation:
> gsub('[[:punct:]]', '', d)
[1] "000" "1059890" "1308247"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With