[R] Number with fixed digit length - zero fill-up

Romain Francois romain.francois at dbmail.com
Mon Feb 1 09:15:29 CET 2010


Here is one way:

 > sprintf( "%08d", 10110 )
[1] "00010110"

Romain

On 02/01/2010 09:00 AM, Jägermeyr, Jonas wrote:
>
> Dear R-help members,
>
> I'm quite new to R and I apologize for my basic question, but I haven't
> been able to find a solution yet.
>
> I try to interpret vector entries as a binary code, but unfortunately
> every first digit which is zero disappears.
>
> So how can I set any number (e.g. x = 10110) to a 8-digit zero fill-up (x
> = 00010110) in order to address digit indices?
>
> Or other way round, how can I make the 'substr' function to count from the
> right hand side?
>
> Thank you.
>
> With kind regards,
>
> Jonas Jägermeyr
>
>
> Department of Geography
> Humboldt-University of Berlin
> jonas.jaegermeyr at geo.hu-berlin.de


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/KfKn : Rcpp 0.7.2
|- http://tr.im/JOlc : External pointers with Rcpp
`- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009



More information about the R-help mailing list