f_pad_zero: Pad Numbers with Leading Zeros

Description Usage Arguments Value Examples

View source: R/f_pad_zero.R

Description

f_pad_zero - Add leading zeros to numbers.

f_pad_left - Add leading character to strings.

f_pad_right - Add trailing character to strings.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
f_pad_zero(x, width = NULL, pad.char = "0", ...)

f_pad_left(x, pad.char = " ", width = NULL, ...)

f_pad_right(x, pad.char = " ", width = NULL, ...)

ff_pad_zero(...)

ff_pad_left(...)

ff_pad_right(...)

Arguments

x

A vector of numbers (or string equivalents).

width

The width to make the stings. Defaults to the maximum number of characters for all elements in x.

pad.char

A character to pad the string with.

...

ignored.

Value

Returns a padded string.

Examples

1
2
3
4
5
6
7
f_pad_zero(c(NA, 1, 12))
f_pad_zero(c(NA, 1, 100, 10, 1000))
f_pad_zero(as.character(c(NA, 1, 100, 10, 1000)))
f_pad_zero(c(NA, 1, 100, 10, 1000, "B", "BB"))
f_pad_left(c(NA, 1, 100, 10, 1000, "B", "BB"), '-')
f_pad_right(c(NA, 1, 100, 10, 1000, "B", "BB"), '-')
f_pad_left(c(NA, 1, 12))

Example output

[1] NA   "01" "12"
[1] NA     "0001" "0100" "0010" "1000"
[1] NA     "0001" "0100" "0010" "1000"
[1] NA     "0001" "0100" "0010" "1000" "000B" "00BB"
[1] NA     "---1" "-100" "--10" "1000" "---B" "--BB"
[1] NA     "1---" "100-" "10--" "1000" "B---" "BB--"
[1] NA   " 1" "12"

numform documentation built on Oct. 10, 2021, 1:10 a.m.