Learn R Programming

miscset (version 1.0.0)

leading0: Numeric to Character with Leading Zero(s)

Description

Transform numeric values to character string prepending leading zero(s).

Usage

leading0(num, digits = 2)

Arguments

num
Numeric vector (character also possible) to transform.
digits
Numeric value of minimum length of output strings.

Value

Character vector with same length of strings of each value. Original "string" is prepended by zero(s). String length is at least max(nchar(as.character(num))).

Examples

Run this code
#

# use with paste to generate strings of equal size:
paste0("observation", leading0(1:10, 3))

#

Run the code above in your browser using DataLab