Take a vector of state identifiers and convert to a common format. Supports all five identifier types in state_ids: USPS abbreviation, full name, FIPS code, AP style abbreviation, and ISO 3166-2 code.

state_convert(x, to = c("abb", "name", "fips", "ap", "iso"))

Arguments

x

A character vector of state identifiers in any supported format.

to

The format returned: "abb", "name", "fips", "ap", or "iso". Defaults to "abb".

Value

A character vector of single format state identifiers.

Examples

state_convert(c("AL", "Vermont", "06"))
#> [1] "AL" "VT" "CA"
state_convert(c("AL", "Vermont", "06"), to = "name")
#> [1] "Alabama"    "Vermont"    "California"
state_convert(c("AL", "Vermont", "06"), to = "fips")
#> [1] "01" "50" "06"
state_convert(c("AL", "Vermont", "06"), to = "ap")
#> [1] "Ala."   "Vt."    "Calif."
state_convert(c("AL", "Vermont", "06"), to = "iso")
#> [1] "US-AL" "US-VT" "US-CA"