How to get rid of varying zeros in a column in R?
I have a df1:
Story Score
1 00678
2 0980
3 1120
4 00067
5 0091
6 123
7 234
8 0234
9 00412
and I would like to get rid of all beginning 0s to have a df2:
Story Score
1 678
2 980
3 1120
4 67
5 91
6 123
7 234
8 234
9 412
Solution 1:
Assuming the Score
column be text, you could use sub
here:
df$Score <- sub("^0+", "", df$Score)
If you intend for Score
to be treated and used as numbers, you also might be able to just cast it to numeric:
df$Score <- as.numeric(df$Score)