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

US_countyNameToFIPS(state = NULL, countyName = NULL)

US_countyFIPSToName(state = NULL, countyFIPS = NULL)

Arguments

state

Vector of state codes, names or FIPS codes. Values will be evaluated to determine the type of input.

countyName

Vector of English language county names.

countyFIPS

Vector of two-digit FIPS codes.

Value

A vector of US county names or FIPS codes.

Examples

library(MazamaSpatialUtils)

US_countyNameToFIPS("Washington", "King")
#> [1] "53033"

# If a single state is provided, it will be recycled
US_countyNameToFIPS("Washington", c("King", "Okanogan"))
#> [1] "53033" "53047"

# Normally, equal length vectors are provided
US_countyNameToFIPS(c("WA", "WA"), c("King", "Okanogan"))
#> [1] "53033" "53047"

# You cannot mix codes!
US_countyNameToFIPS(c("WA", "Washington"), c("King", "Okanogan"))
#> [1] "53033" NA     

# No 'Okanogan' county in Texas
US_countyNameToFIPS(c("WA", "TX"), c("King", "Okanogan"))
#> [1] "53033" NA     

# But there is a 'King' county in Texas
US_countyNameToFIPS(c("TX", "WA"), c("King", "Okanogan"))
#> [1] "48269" "53047"
US_countyNameToFIPS(c("TX", "WA"), c("King", "King"))
#> [1] "48269" "53033"

# The US_countyFIPSToName() function is included for symmetry but a
# more typical usage of a 5-digit county FIPS would be to extract it from
# the US_countyCodes package dataset:

US_countyCodes %>% dplyr::filter(countyFIPS == 53033)
#>   stateCode stateFIPS countyName countyFIPS
#> 1        WA        53       King      53033