
sprintf
that pads the front end of strings with spaces or 0s.
Useful for creating multiple uniform directories that
will maintain correct order.
pad(x, padding = max(nchar(as.character(x))), sort = TRUE, type = "detect")
TRUE
the outcome is
sorted."detect"
,
"numeric"
, "character"
, "d"
or
"s"
. If numeric zeros are padded. If character
spaces are padded. The detect
attempts to
determine if x is numeric (d) or not (s).sprintf
pad(sample(1:10, 6))
pad(sample(1:10, 6), sort=FALSE)
pad(as.character(sample(1:10, 6)))
pad(as.character(sample(1:10, 6)), 4)
Run the code above in your browser using DataLab