remove leading 0s with stringr in R

Alex picture Alex · Mar 9, 2018 · Viewed 9.6k times · Source

I have the following data

id
00001
00010
00022
07432

I would like to remove the leading 0s so the data would like like the following

id
1
10
22
7432

Answer

Marius picture Marius · Mar 9, 2018

Using the new str_remove function in stringr:

id = str_remove(id, "^0+")