[R] Leading zeros

David Winsemius dwinsemius at comcast.net
Fri Aug 19 17:51:08 CEST 2011


On Aug 19, 2011, at 11:17 AM, David Winsemius wrote:

>
> On Aug 19, 2011, at 11:12 AM, Vasco Cadavez wrote:
>
>> Hello,
>> I have a dataset with an Id columns like:
>> 4/3003
>> 55/333
>> 66/22
>> I want to put leading zeros to get:
>> 00000004/3003
>> 000000055/333
>> 0000000066/22
>>
>> How can I solve this?
>
> ?sprintf
> ?formatC
>
I may have been too quick. Padding with leading zeros using sprintf is  
described for numeric but not for character types. There are several  
character padding funcitons when you search:

http://search.r-project.org/cgi-bin/namazu.cgi?query=pad+character++&max=100&result=normal&sort=score&idxname=functions&idxname=Rhelp08&idxname=Rhelp10&idxname=Rhelp02




> -- 
>
> David Winsemius, MD
> West Hartford, CT
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list