| leading_zero | R Documentation |
This function ensures that fixed width data is the right length by padding zeroes to the front of values. This is a common problem with fixed width data after importing into R as non-character type.
leading_zero(x, digits = 2)
x |
a vector of numeric data that should be fixed width but is missing leading zeroes. |
digits |
an integer representing the desired width of |
If x contains negative values, digits is widened by 1 for
the entire vector so that all values share a uniform total width, with the negative
sign occupying one character position. For example,
leading_zero(c(-5, 42), digits = 2) returns c("-05", "042") — both
width 3. Mixed-sign vectors are supported but produce width digits + 1
for all elements.
A character vector of length digits
Jason P. Becker
Jared E. Knowles
a <- seq(1,10)
a <- leading_zero(a, digits = 3)
a
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.