lead.zeroes: Add leading zeroes as needed

View source: R/lead.zeroes.R

lead.zeroesR Documentation

Add leading zeroes as needed

Description

Returns the vector that was supplied, but with leading zeroes added where needed to make all elements have right number of characters.

Usage

lead.zeroes(fips, length.desired = NULL)

Arguments

fips

Character vector, which can be FIPS codes or other data. Required.

length.desired

NOT USED ANYMORE. INFERRED. Was a single numeric value (recycled), or vector of numbers, required, specifying how many characters long each returned string should be.

Details

This function can be useful in working with Census data where FIPS codes are often used. Moving data to and from a spreadsheet can remove leading zeroes that may be necessary for proper data management. This can apply to e.g., FIPS code for a block, block group, tract, county, or state. Note: Number of digits in FIPS codes, assuming leading zeroes are there:
state 2 (2 cumulative)
county 3 (5 cum)
tract 6 (11 cum) (note 11 digits is ambiguous if not sure leading zero is there)
block group 1 (12 cum) (note 12 digits is ambiguous if not sure leading zero is there)
block 1 (13 cum)

Value

Returns a vector of same length as input parameter, NA for NA input elements

Examples

lead.zeroes(c('234','01234','3', NA, 'TEXT'), 5)

ejanalysis/analyze.stuff documentation built on April 2, 2024, 10:10 a.m.