I have a string of numbers and characters
c2 = "list of 2nd C2 H2O 1 12 123"
I need to get rid of all digits that are actual numbers, i.e. 1, 12, 123, but not the ones that are part of a character set, i.e. 2nd, C2, H2O.
So far, the best solution I have come up with is this
gsub("? [[:digit:]]*", " ", c2)
"list of nd C2 H2O "
It successfully gets rid of 1 12 123, while retaining C2 H2O. However, I lost 2 in 2nd.
I am at my wits end.
Thanks!
Try this:
> gsub("\\b\\d+\\b", "", c2)
[1] "list of 2nd C2 H2O "
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments