Hi, What's one way to convert an integer to a string with preceding 0's? such that '13' becomes '00000000013' to be put into a string I've tried formatC, but they removes all the zeros and replace it with blanks Thanks -- Regards, Anh Tran [[alternative HTML version deleted]]
Try something like one of these (as documented in ?formatC) > formatC(13, flag="0", width=10) [1] "0000000013" > sprintf("%010g", 13) [1] "0000000013" > Anh Tran wrote:> Hi, > What's one way to convert an integer to a string with preceding 0's? > such that > '13' becomes '00000000013' > to be put into a string > > I've tried formatC, but they removes all the zeros and replace it with > blanks > > Thanks >
Anh Tran wrote:> Hi, > What's one way to convert an integer to a string with preceding 0's? > such that > '13' becomes '00000000013' > to be put into a string > > I've tried formatC, but they removes all the zeros and replace it with > blanksNot so for me: formatC(13, digits=10, flag="0") Uwe LIgges> > Thanks >
Thanks. formatC(flag) works. But it's awefully slow. I try to do that for 65000 numbers (generating ID for each item) and it seems like forever. Is there any faster way? Thank all. Anh Tran On Mon, May 12, 2008 at 2:36 PM, Uwe Ligges < ligges@statistik.uni-dortmund.de> wrote:> > > Anh Tran wrote: > > > Hi, > > What's one way to convert an integer to a string with preceding 0's? > > such that > > '13' becomes '00000000013' > > to be put into a string > > > > I've tried formatC, but they removes all the zeros and replace it with > > blanks > > > > Not so for me: > > formatC(13, digits=10, flag="0") > > Uwe LIgges > > > > > Thanks > > > >-- Regards, Anh Tran [[alternative HTML version deleted]]
On May 12, 2008, at 5:22 PM, Anh Tran wrote:> Hi, > What's one way to convert an integer to a string with preceding 0's? > such that > '13' becomes '00000000013' > to be put into a string > > I've tried formatC, but they removes all the zeros and replace it with > blanksformatC(13, width=10, format="d", flag="0")> Thanks > > -- > Regards, > Anh TranHaris Skiadas Department of Mathematics and Computer Science Hanover College
Anh Tran wrote:> Hi, > What's one way to convert an integer to a string with preceding 0's? > such that > '13' becomes '00000000013' > to be put into a string > > I've tried formatC, but they removes all the zeros and replace it with > blanksHi, try sprintf: >i=13 > cat(sprintf("%05d\n", i)) 00013 > HTH, Esmail