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

padW0

Pad with 0's.


Description

Sometimes we receive this c(1, 22, 131) and we need character variables of the same size, such as c("001", "022", "131"). This happens if a user has mistakenly converted a zip code (US regional identifier) like "00231" to a number. This function converts the number back to a 0 padded string.

Usage

padW0(x)

Arguments

x

a numeric variable.

Details

This works differently if the number provided is an integer, or a character string. Integers are left padded with the character "0". A character string will be left-padded with blanks.

Value

A character string vector padded with 0's

Author(s)

Paul Johnson <pauljohn@ku.edu>

Examples

x <- c(1 , 11, 22, 121, 14141, 31)
(xpad <- padW0(x))
x <- rpois(7, lambda = 11)
(xpad <- padW0(x))
x <- c("Alabama", "Iowa", "Washington")

rockchalk

Regression Estimation and Presentation

v1.8.144
GPL (>= 3.0)
Authors
Paul E. Johnson [aut, cre], Gabor Grothendieck [ctb]
Initial release
2019-03-07

We don't support your browser anymore

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