padInteger function

prefix integers with leading zeros

prefix integers with leading zeros

padInteger(x, padCharacter = "0", useNchar = NULL, ...)

Arguments

  • x: integer, numeric, or character vector. In reality, only nchar(x) is required to determine padding.
  • padCharacter: character with nchar(padCharacter)==1, used to pad each digit as a prefix.
  • useNchar: NULL or integer number of digits used, or if the maximum nchar(x) is higher, that number of digits is used. Note useNchar 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.

Returns

character vector of length(x).

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.

Examples

padInteger(c(1, 10, 20, 300, 5000))

See Also

Other jam string functions: asSize(), breaksByVector(), fillBlanks(), formatInt(), gsubOrdered(), gsubs(), makeNames(), nameVector(), nameVectorN(), padString(), pasteByRow(), pasteByRowOrdered(), sizeAsNum(), tcount(), ucfirst()

  • Maintainer: James M. Ward
  • License: MIT + file LICENSE
  • Last published: 2025-03-23