I have a list of alphanumeric characters that looks like:
x <-c('ACO2', 'BCKDHB456', 'CD444')
I would like the following output:
x <-c('ACO', 'BCKDHB', 'CD')
Any suggestions?
# dput(tmp2) structure(c(432L, 326L, 217L, 371L, 179L, 182L, 188L, 268L, 255L,..., ), class = "factor")
To remove dot and number at the end of the string, we can use gsub function. It will search for the pattern of dot and number at the end of the string in the vector then removal of the pattern can be done by using double quotes without space.
You can use gsub
for this:
gsub('[[:digit:]]+', '', x)
or
gsub('[0-9]+', '', x) # [1] "ACO" "BCKDHB" "CD"
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