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?
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?
We can use sub
df1[,1] <- sub("^.", "", df1[,1])
Or use substring
substring(df1[,1],2)
df1 <- data.frame(Col1 = c("M999-00001", "M999-0000"), stringsAsFactors=FALSE)
You can use gsub function for the same
Col1 <- gsub("[A-z]","",Col1)
[1] "999-00001" "999-0000"
Col1 = c("M999-00001", "M999-0000")
df %>%
transform(col_name=str_replace(col_name,"M",""))
Use it only if you have installed stringr
library and magrittr
library
© 2022 - 2024 — McMap. All rights reserved.
substr
. – Afoot