Converts a vector of US state names or codes from one system to another reuturning NA where no match is found.

US_stateCodeToName(stateCode = NULL)

US_stateCodeToFIPS(stateCode = NULL)

US_stateFIPSToName(stateFIPS = NULL)

US_stateFIPSToCode(stateFIPS = NULL)

US_stateNameToCode(stateName = NULL)

US_stateNameToFIPS(stateName = NULL)

Arguments

stateCode

Vector of ISO 3166-2 alpha-2 codes.

stateFIPS

Vector of two-digit FIPS codes.

stateName

Vector of English language state names.

Value

A vector of US state names or codes.

Examples

library(MazamaSpatialUtils)

US_stateNameToCode("Washington")
#> [1] "WA"
US_stateNameToFIPS("Washington")
#> [1] "53"

postalCodes <- sample(US_stateCodes$stateCode, 30)

data.frame(
  name = US_stateCodeToName(postalCodes),
  code = postalCodes,
  FIPS = US_stateCodeToFIPS(postalCodes)
)
#>              name code FIPS
#> 1   Massachusetts   MA   25
#> 2        Oklahoma   OK   40
#> 3       Wisconsin   WI   55
#> 4      California   CA   06
#> 5       Minnesota   MN   27
#> 6  South Carolina   SC   45
#> 7       Louisiana   LA   22
#> 8           Idaho   ID   16
#> 9          Oregon   OR   41
#> 10         Kansas   KS   20
#> 11           Iowa   IA   19
#> 12       Nebraska   NE   31
#> 13         Alaska   AK   02
#> 14       Maryland   MD   24
#> 15           Utah   UT   49
#> 16       Kentucky   KY   21
#> 17         Nevada   NV   32
#> 18    Mississippi   MS   28
#> 19        Montana   MT   30
#> 20          Texas   TX   48
#> 21   Pennsylvania   PA   42
#> 22        Alabama   AL   01
#> 23           Ohio   OH   39
#> 24     New Jersey   NJ   34
#> 25       Missouri   MO   29
#> 26        Florida   FL   12
#> 27  West Virginia   WV   54
#> 28        Georgia   GA   13
#> 29       Arkansas   AR   05
#> 30      Tennessee   TN   47