Reputation: 992
I have a column of alphanumeric data and i have to remove the last consecutive digits. It could be of any length.
Input:
dlxcp01
dlcs8012
fg2fdes1
Desired Output:
dlxcp
dlcs
fg2fdes
As i have large dataset, a right code would do it better.
Upvotes: 0
Views: 48
Reputation: 7469
Use the gsub()
function:
text <- c('dlxcp01', 'dlcs8012', 'fg2fdes1')
gsub('[0-9]*$', "", text)
[1] "dlxcp" "dlcs" "fg2fdes"
Upvotes: 1
Reputation: 174796
Use sub function.
sub("[0-9]+$", "", x)
or
sub("[[:digit:]]+$", "", x)
Upvotes: 1