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).A convenience wrapper for sprintf
that pads the front end
of strings with spaces or 0s. Useful for creating multiple uniform directories
that will maintain correct order.
pad
is a wrapper for the sprintf
function.
pad
may behave differently on various platforms in accordance with the
documentation for sprintf
: "actual implementation will
follow the C99 standard and fine details (especially the behaviour under user
error) may depend on the platform." See sprintf
for more
information.
pad(sample(1:10, 10))[1] "01" "02" "03" "04" "05" "06" "07" "08" "09" "10"pad(sample(1:10, 10), sort=FALSE)[1] "10" "01" "02" "06" "07" "08" "05" "09" "03" "04"pad(as.character(sample(1:10, 10)))[1] " 1" " 2" " 3" " 4" " 5" " 6" " 7" " 8" " 9" "10"pad(as.character(sample(1:10, 10)), sort=FALSE)[1] " 5" " 1" " 7" " 3" " 2" "10" " 9" " 8" " 6" " 4"pad(as.character(sample(1:10, 10)), 4)[1] " 1" " 2" " 3" " 4" " 5" " 6" " 7" " 8" " 9" " 10"pad(month.name)[1] " May" " July" " June" " April" " March" " August" " January" " October" " December" " February" [11] " November" "September"
sprintf