Skip to contents

Pad a string to minimum width

Usage

strPad(x, width, side = c("left", "right"), pad = " ")

Arguments

x

character. Character vector that does not contain NA or empty strings.

width

integer(1). Padding width.

side

character(1). Apply padding to the left or right side.

pad

character(1). Single padding character.

Value

character.

Note

Updated 2023-09-21.

See also

Examples

x <- c("1", "10", "100")
width <- max(nchar(x))
x <- strPad(x = x, width = width, side = "left", pad = "0")
print(x)
#> [1] "001" "010" "100"