Look up FIPS or CBSA codes by county or metropolitan area names,
respectively; these functions are based on grep()
, and hence allow for
regular expressions.
Vector of county or metropolitan area names to look up.
Arguments to pass to grep()
, with the same
defaults as in the latter function. Hence, by default, regular expressions
are used; to match against a fixed string (no regular expressions), set
fixed = TRUE
.
If "first", then only the first match for each name is returned. If "all", then all matches for each name are returned.
Two letter state abbreviation (case insensitive) indicating a
parent state used to restrict the search. For example, when state = "NY"
,
then name_to_fips()
searches only over only counties lying in New York
state, whereas name_to_cbsa()
searches over the metropolitan areas lying,
either fully or partially (as a metropolitan area can span several states),
in New York state. If NULL
, the default, then the search is performed
US-wide (not restricted to any state in particular).
A vector of FIPS or CBSA codes if ties_method
equals "first", and a
list of FIPS or CBSA codes otherwise.
name_to_fips("Allegheny")
#> Allegheny County
#> "42003"
name_to_cbsa("Pittsburgh")
#> Pittsburgh, PA
#> "38300"
name_to_fips("Miami")
#> Warning: Some inputs were not uniquely matched; returning only the first match in each case.
#> Miami-Dade County
#> "12086"
name_to_fips("Miami", ties_method = "all")
#> [[1]]
#> Miami-Dade County Miami County Miami County Miami County
#> "12086" "18103" "20121" "39109"
#>
name_to_fips(c("Allegheny", "Miami", "New "), ties_method = "all")
#> [[1]]
#> Allegheny County
#> "42003"
#>
#> [[2]]
#> Miami-Dade County Miami County Miami County Miami County
#> "12086" "18103" "20121" "39109"
#>
#> [[3]]
#> New Haven County New London County New Castle County New Madrid County
#> "09009" "09011" "10003" "29143"
#> New Hampshire New Jersey New Mexico New York
#> "33000" "34000" "35000" "36000"
#> New York County New Hanover County New Kent County
#> "36061" "37129" "51127"
#>