Look up FIPS codes by state abbreviations (including District of Columbia and Puerto Rico); this function is based on grep(), and hence allows for regular expressions.

abbr_to_fips(
  abbr,
  ignore.case = TRUE,
  perl = FALSE,
  fixed = FALSE,
  ties_method = c("first", "all")
)

Arguments

abbr

Vector of state abbreviations to look up.

ignore.case, perl, fixed

Arguments to pass to grep(), with the same defaults as in the latter function, except for ignore.case = TRUE. Hence, by default, regular expressions are used; to match against a fixed string (no regular expressions), set fixed = TRUE.

ties_method

If "first", then only the first match for each name is returned. If "all", then all matches for each name are returned.

Value

A vector of FIPS codes if ties_method equals "first", and a list of FIPS codes otherwise. These FIPS codes have five digits (ending in "000").

See also

Examples

abbr_to_fips("PA")
#>      PA 
#> "42000" 
abbr_to_fips(c("PA", "PR", "DC"))
#>      PA      PR      DC 
#> "42000" "72000" "11000" 

# Note that name_to_fips() works for state names too:
name_to_fips("^Pennsylvania$")
#> Pennsylvania 
#>      "42000"