Skip to content
Prev 237255 / 398500 Next

Truncating leading zeros in strings

On Oct 7, 2010, at 9:57 AM, E. Paul Wileyto wrote:

            
as.integer doesn't work? (If you are dealing in different base than  
10, then you really should say so.)

 > as.integer("0000123")
[1] 123

Or pass through sub("^[0]+", "", vals)
 > sub("^[0]+", "", "0000123")
[1] "123"

An example is expected in such situations. Please do now read the  
Posting Guide.