I am trying to strip the characters from a string that contains either just characters or some has a number attached as well. For example:
abc <- c("a1","bc","b2","ab","ma")
From this I would like to use some kind of ifelse statement to return only the letters as a new variable and remove the numbers to look like this:
abc <- c("a","bc","b","ab","ma")
I found sources which helped me strip a certain number of characters form a string but I am struggling with this one, as I have over 9mil observations some just two letters (as I want them i.e "MA") but some has a number as the second character (i.e "M6" of the string, but would like it to return "M" if this is the case for this observation or keep it the way it is if it is already two characters). I would much appreciate your advice. Thank you.
Aucun commentaire:
Enregistrer un commentaire