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


I am new to R. I thing this will be simple, but I don't yet know my way around.

I am generating character strings from the system clock that represent integers, and I want to convert them to integer values. Strtoi works well, except when there are leading zeros on the string. Could anyone suggest a way to remove those leading zeros?

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.
--

David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to