[R] add zero in front of numbers

2011-04-04 Thread Yan Jiao
Dear R users,

I need to add 0 in front of a series of numbers, e.g. 1-001, 19-019,
Is there a fast way of doing that?

Many thanks

yan

[[alternative HTML version deleted]]

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


Re: [R] add zero in front of numbers

2011-04-04 Thread Luis Ridao
Have a look at

?formatC

On Mon, Apr 4, 2011 at 11:35 AM, Yan Jiao y.j...@ucl.ac.uk wrote:

 Dear R users,

 I need to add 0 in front of a series of numbers, e.g. 1-001, 19-019,
 Is there a fast way of doing that?

 Many thanks

 yan

[[alternative HTML version deleted]]

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


[[alternative HTML version deleted]]

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


Re: [R] add zero in front of numbers

2011-04-04 Thread January Weiner
Dear Yan,

apart from formatC, you can also use sprintf, which works almost
exactly like the C sprintf function. To convert an integer x to a
string with 5 leading 0s, you do:

sprintf( %05d, x )

Best regards,

j.

On Mon, Apr 4, 2011 at 12:35 PM, Yan Jiao y.j...@ucl.ac.uk wrote:
 Dear R users,

 I need to add 0 in front of a series of numbers, e.g. 1-001, 19-019,
 Is there a fast way of doing that?

 Many thanks

 yan

        [[alternative HTML version deleted]]

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




-- 
 Dr. January Weiner 3 --
Max Planck Institute for Infection Biology
Charitéplatz 1
D-10117 Berlin, Germany
Web   : www.mpiib-berlin.mpg.de
Tel     : +49-30-28460514

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


Re: [R] add zero in front of numbers

2011-04-04 Thread Uwe Ligges



On 04.04.2011 12:35, Yan Jiao wrote:

Dear R users,

I need to add 0 in front of a series of numbers, e.g. 1-001, 19-019,
Is there a fast way of doing that?


formatC(c(1, 19), flag=0, width=3)

Uwe Ligges


Many thanks

yan

[[alternative HTML version deleted]]

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


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