[R] convert "1", "10", and "100" to "0001", "0010", "0100" etc.

David Winsemius dwinsemius at comcast.net
Sat Sep 11 04:36:30 CEST 2010


On Sep 10, 2010, at 10:05 PM, Peng, C wrote:

>
> I mean to display 001,010, ..., as there are.  In other words,  
> whether there
> is a function, say func(), such that func(001,010) displays 001, 010.

Not hard to construct one, but does not behave properly in the sub- 
unity decimal range. Not surprising. It did better in the range of  
values from the integer class than I thought it would.

 > func4 <- function(x) cat(sprintf("%05.0f", x))
 > func4(10)
00010
 > func5 <- function(x) cat(sprintf("%05.0f", x))
 > func5(100)
00100
 > func5(100000)
100000
 > func5(100000000)
100000000
 > func5(0.001)
00000
 > func5(-3)
-0003
 > func5(-3000000)
-3000000

-- 
David.



More information about the R-help mailing list