pad | R Documentation |
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(x, padding = max(nchar(as.character(x))), sort = TRUE, type = "detect")
x |
A character, factor, numeric vector. |
padding |
Number of characters to pad. Default makes all elements of a string the number of characters of the element with the maximum characters. |
sort |
logical. If |
type |
A character string of |
Returns a character vector every element padded with 0/spaces.
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.
sprintf
pad(sample(1:10, 10))
pad(sample(1:10, 10), sort=FALSE)
pad(as.character(sample(1:10, 10)))
pad(as.character(sample(1:10, 10)), sort=FALSE)
pad(as.character(sample(1:10, 10)), 4)
pad(month.name)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.