pad.zero: Pad String With Leading Zeros

View source: R/pad.zero.R

pad.zeroR Documentation

Pad String With Leading Zeros

Description

Pads each element of a numeric vector, or a vector that can be coerced to numeric, so that it is a string of a minimum width by adding leading 0s.

Usage

pad.zero(x, width)

Arguments

x

a numeric vector or vector that can be coerced to numeric.

width

minimum width desired for each string.

Details

Non-integers are truncated towards 0.

For negative integers, the negative sign is counted towards the string length.

Integers that are already as long or longer than width are unaffected.

Value

character vector of digit strings in which 0s have been prepended to each string to make it at least width characters long.

Examples

pad.zero(c('3','80','155'), width=2)
pad.zero(20, width=3)

sfraundorf/psycholing documentation built on April 23, 2022, 2:50 a.m.