prefix integers with leading zeros
Arguments
- x
integer,numeric, orcharactervector. In reality, onlynchar(x)is required to determine padding.- padCharacter
characterwith nchar(padCharacter)==1, used to pad each digit as a prefix.- useNchar
NULLorintegernumber of digits used, or if the maximumnchar(x)is higher, that number of digits is used. NoteuseNcharis mostly useful when all numbers are less than 10, but the desired output is to have a fixed number of digits 2 or higher.- ...
additional parameters are ignored.
Details
The purpose of this function is to pad integer numbers so they contain a consistent number of digits, which is helpful when sorting values as character strings.
See also
Other jam string functions:
asSize(),
breaksByVector(),
fillBlanks(),
formatInt(),
gsubOrdered(),
gsubs(),
makeNames(),
nameVector(),
nameVectorN(),
padString(),
pasteByRow(),
pasteByRowOrdered(),
sizeAsNum(),
tcount(),
ucfirst()
Examples
padInteger(c(1, 10, 20, 300, 5000))
#> [1] "0001" "0010" "0020" "0300" "5000"