Miyii Miyii - 3 months ago 9
R Question

Remove prefix from all data in a single column in R

I would have a column where the data looks like this:

M999-00001
M999-00002
...


Is there a way to remove all the 'M's in the column in R?

Answer

We can use sub

df1[,1] <- sub("^.", "", df1[,1])

Or use substring

substring(df1[,1],2)

data

df1 <- data.frame(Col1 = c("M999-00001", "M999-0000"), stringsAsFactors=FALSE)
Comments