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).Returns a character vector every element padded with 0/spaces.
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(sample(1:10, 10))[1] "01" "02" "03" "04" "05" "06" "07" "08" "09" "10"pad(sample(1:10, 10), sort=FALSE)[1] "06" "02" "10" "01" "03" "09" "04" "05" "08" "07"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] " 3" " 6" " 9" " 1" " 4" " 2" " 8" "10" " 5" " 7"pad(as.character(sample(1:10, 10)), 4)[1] " 1" " 2" " 3" " 4" " 5" " 6" " 7" " 8" " 9" " 10"
sprintf