Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

pad0

Pad Values with Leading Zeroes


Description

Pad numbers and/or text with leading and/or trailing zeroes.

Usage

pad0(x, n, f = 0)

Arguments

x

vector of numbers and/or strings

n

number of text characters representing a padded integer

f

factor of 10 transformation on x before padding

Details

Converts numbers (or text coerced to numeric) to integers and then to text, and pads them with leading zeroes. If the factor f is >0, then trailing zeroes are also added.

Value

If length(f)==1 or length(x)==1, the function returns a character vector representing x with leading zeroes.

If both f and x have lengths >1, then a list of character vectors indexed by f is returned.

Author(s)

Rowan Haigh, Pacific Biological Station, Fisheries and Oceans Canada, Nanaimo BC

See Also

Examples

local(envir=.PBSmodEnv,expr={
  resetGraph(); x <- pad0(x=123,n=10,f=0:7);
  addLabel(.5,.5,paste(x,collapse="\n"),cex=1.5);
})

PBSmodelling

GUI Tools Made Easy: Interact with Models and Explore Data

v2.68.8
GPL (>= 2)
Authors
Jon T. Schnute [aut], Alex Couture-Beil [aut], Rowan Haigh [aut, cre], Nicholas Boers [ctb], Anisa Egeli [ctb], A. R. Kronlund [ctb], Steve Martell [ctb], Norm Olsen [ctb]
Initial release
2019-03-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.