Learn R Programming

wru (version 3.0.3)

as_fips_code: Convert between state names, postal abbreviations, and FIPS codes

Description

Convert between state names, postal abbreviations, and FIPS codes

Usage

as_fips_code(x)

as_state_abbreviation(x)

Value

as_state_fips_code()

A character vector of two-digit FIPS codes. One-digit FIPS codes are prefixed with a leading zero, e.g., "06" for California.

as_state_abbreviation()

A character vector of two-letter postal abbreviations, e.g., "CA" for California.

Arguments

x

A numeric or character vector of state names, postal abbreviations, or FIPS codes. Matches for state names and abbreviations are not case sensitive. FIPS codes may be matched from numeric or character vectors, with or without leading zeroes.

Examples

Run this code
as_fips_code("california")
as_state_abbreviation("california")

# Character vector matches ignore case
as_fips_code(c("DC", "Md", "va"))
as_state_abbreviation(c("district of columbia", "Maryland", "VIRGINIA"))

# Note that `3` and `7` are standardized to `NA`,
# because no state is assigned those FIPS codes
as_fips_code(1:10)
as_state_abbreviation(1:10)

# You can even mix methods in the same vector
as_fips_code(c("utah", "NM", 8, "04"))
as_state_abbreviation(c("utah", "NM", 8, "04"))

Run the code above in your browser using DataLab