Add n
leading zeros to a numeric sequence. This is useful to create a
character vector to rename files in a folder.
Arguments
- x
A numeric vector or a list of numeric vectors.
- n
The number of leading zeros to add. Defaults to 3
.
Value
A character vector or a list of character vectors.
Examples
library(pliman)
leading_zeros(1:5)
#> [1] "001" "002" "003" "004" "005"
leading_zeros(list(a = 1:3,
b = 1:5),
n = 2)
#> $a
#> [1] "01" "02" "03"
#>
#> $b
#> [1] "01" "02" "03" "04" "05"
#>