I have a column in a dataframe where the values are letter-number combinations like G1, K8, A132, etc. I want to split the letter from the number but retain the number as a single number. I have been using strsplit but this gives a list of values as seen below where I would liek to have the output of G
and 10
:
x <- "G10"
strsplit(x, "")[[1]][1]
"G"
strsplit(x, "")[[1]][-1]
"1" "0"
this leads to the predictable downstream problems when I try to use the numbers as numbers. Here is a paste
example where I would like to get "somethingelse_10":
z <-strsplit(x, "")[[1]][-1]
paste("somethingelse",z, sep="_")
"somethingelse_1" "somethingelse_0"
Is there an easy way to split numbers from letters?