Re: [R] Beginner's question: number formatting

2008-10-17 Thread Michal Figurski
Thank you all for quick responses, This was very helpful. I knew there was a simple way! -- Michal J. Figurski Prof Brian Ripley wrote: sprintf("%03d", 2) formatC(2, width=3, flag="0") both give [1] "002" On Fri, 17 Oct 2008, Michal Figurski wrote: Hello R-helpers, I have a problem with

Re: [R] Beginner's question: number formatting

2008-10-17 Thread Prof Brian Ripley
sprintf("%03d", 2) formatC(2, width=3, flag="0") both give [1] "002" On Fri, 17 Oct 2008, Michal Figurski wrote: Hello R-helpers, I have a problem with formatting a single number to show leading zeros. For example, I want "2" displayed as "002". I hope you meant that you want 2, not "2",

Re: [R] Beginner's question: number formatting

2008-10-17 Thread jim holtman
?sprintf > x <- c(1,10,11,100) > sprintf("%03d", x) [1] "001" "010" "011" "100" On Fri, Oct 17, 2008 at 1:55 PM, Michal Figurski <[EMAIL PROTECTED]> wrote: > Hello R-helpers, > > I have a problem with formatting a single number to show leading zeros. For > example, I want "2" displayed as "002".

[R] Beginner's question: number formatting

2008-10-17 Thread Michal Figurski
Hello R-helpers, I have a problem with formatting a single number to show leading zeros. For example, I want "2" displayed as "002". My numbers have 1 to 3 digits and I would like them all to display 3 digits for printing. I know I could use "paste" in a loop with several "if"s, but I was wo