[R] Formatting numbers

Andris Jankevics andza at osi.lv
Mon Apr 27 12:53:34 CEST 2009


Hi, try this

A <- c(1:1000)
A <- paste ("000",A,sep="")
substr (A,nchar(A)-3,nchar(A))


Best regards,
Andris Jankevics


On Mon, Apr 27, 2009 at 12:35 PM, Mario dos Reis <mdosrei at nimr.mrc.ac.uk> 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.
>
> Cheers!
> Mario.




More information about the R-help mailing list