I have a vector of character data. Most of the elements in the vector consist of one or more letters followed by one or more numbers. I wish to split each element in the
A slightly more elegant way (without any external packages):
> x = c("aaa", "b11", "b21", "b101", "b111", "ccc1", "ffffd1", "ccc20", "ffffd13")
> gsub('\\D','', x) # replaces non-digits with blancs
[1] "" "11" "21" "101" "111" "1" "1" "20" "13"
> gsub('\\d','', x) # replaces digits with blanks
[1] "aaa" "b" "b" "b" "b" "ccc" "ffffd" "ccc" "ffffd"