The Federal Information Processing Standards (fips) codes are available as 5-digit, 0-padded numbers. To standardize these codes for joins across datasets, one may need to convert raw integers (non-0-padded) to 5-digit numeric strings. This function does that.

integer_to_fips(v)

county_to_state_fips(fips)

Arguments

v

integer vector of length 1 or more

fips

character vector of county or state-level fips (5-digit zero-padded string) to be converted

Value

character vector with each member a 0-padded representation of the original integer value.

Details

A county-level fips code can be truncated to a state fips code since the last two digits in the county fips code are the state fips code.

Functions

  • county_to_state_fips:

References

List of United States FIPS codes by county: https://en.wikipedia.org/wiki/List_of_United_States_FIPS_codes_by_county.

Author

Sean Davis seandavi@gmail.com

Examples

integer_to_fips(50)
#> [1] "00050"
class(integer_to_fips(50))
#> [1] "character"
nchar(integer_to_fips(50))==5
#> [1] TRUE
integer_to_fips(sample(1:50000,5))
#> [1] "10110" "25224" "37784" "03427" "26528"

sl = county_to_state_fips('00050')
sl
#> [1] "00000"
sl_from_cy = county_to_state_fips('12350')
sl_from_cy
#> [1] "00012"
sl == sl_from_cy
#> [1] FALSE