pad: Pad a number with leading zeros

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Convert a number to a string, and pad out the resulting character with "0" at the start.

Usage

1
pad(int, strWidth = NULL, atEnd = FALSE)

Arguments

int

a numeric vector, or character vector of numbers

strWidth

the desired width. If NULL, and length(int)>1, then this is determined automatically. If NULL, and length(int)==1, then a single “0” is added.

atEnd

logical: pad at the end (TRUE), or start (FALSE)?

Details

Can supply strWidth to specify the number of characters desired in the final string. If it's not supplied, then a single "0" is prepended. If int is a vector of numbers, strWidth is automatically set so that they all have the same number of characters.

Value

a charcter vector, all with the same nchar.

Author(s)

Mark Cowley, 2005-09-21

See Also

sprintf

Examples

1
2
3
pad(1, 2)
pad(1:10, 2)
pad(1:10)

drmjc/mjcbase documentation built on May 15, 2019, 2:27 p.m.