[R] pad leading zeros in front of strings
R. Michael Weylandt
michael.weylandt at gmail.com
Tue May 22 20:49:19 CEST 2012
I think once upon a time this was found to be OS-dependent since it
calls the system's C sprintf() -- I get the leading zeros on Mac. I
presume you're on Windows?
Michael
On Tue, May 22, 2012 at 2:41 PM, Hui Du <Hui.Du at dataventures.com> wrote:
> Dear All,
>
> This question sounds very simple but I don't know where I am wrong. I just want to pad leading zeros in some string, for example, "123" becomes "00123". What is wrong if I do following?
>
>> sprintf("%05s", "123")
> [1] " 123"
>
>
> It didn't return "00123", instead it padded with 'blank'.
>
>
> Thank you for your help in advance.
>
> HXD
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
More information about the R-help
mailing list