[R] Formatting numbers

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Mon Apr 27 12:44:37 CEST 2009


Mario dos Reis wrote:
> I've been trough the R documentation for about half an hour and it's
> not clear to me how to do this:
>
> I need to format to character a series of integers from 1 to 1000, and
> I like them to look like
>
> "0001" "0002", "0059", "0123" and so on. Padded with zeroes to have
> four digits.
    # dummy data
    x = sample(100, 10)

    # formatting
    sprintf('%04d', x)

vQ




More information about the R-help mailing list