prefix integers with leading zeros
Arguments
- x
integer
,numeric
, orcharacter
vector. In reality, onlynchar(x)
is required to determine padding.- padCharacter
character
with nchar(padCharacter)==1, used to pad each digit as a prefix.- useNchar
NULL
orinteger
number of digits used, or if the maximumnchar(x)
is higher, that number of digits is used. NoteuseNchar
is 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"