Skip to content
Prev 301469 / 398503 Next

add leading zeros

Hello,

Here is a function that I wrote some time ago.

# pad with zeros
padz <- function(x, width=max(nchar(x)), fill="0")
     gsub(" ", fill, formatC(x, width=width))
##------------- test
padz( c(1, 10, 100) )
padz(1:10, 4)
##------------- non-sense
padz(-5:0, 4)
padz(runif(10))


Hope this helps,

Rui Barradas

Em 27-07-2012 02:08, LCOG1 escreveu: