Get FIPS codes from names of states or counties inverse of fips2name(), 1-to-1 map statename, ST, countyname to FIPS of each
Source:R/FIPS_FUNCTIONS.R
name2fips.Rd
Get FIPS codes from names of states or counties inverse of fips2name(), 1-to-1 map statename, ST, countyname to FIPS of each
Arguments
- x
vector of 1 or more exact names of states or ST abbreviations or countynames that include the comma and state abbrev., like "Harris County, TX" (not the same as where ST is separate in
fips_counties_from_countyname()
) Ignores case.- exact
if TRUE, query must match exactly but set to FALSE if you want partial matching and possibly more than one result for a query term x
- usegrep
passed to
fips_place_from_placename()
and if TRUE, helps find partial matches- geocoding
passed to
fips_place_from_placename()
- details
set to TRUE to return a table of details on places instead of just the fips vector
Details
CAUTION - for cities/ towns/ CDPs/ etc. (census places), this currently assumes a placename,ST occurs only once per state, but there are exceptions like townships in PA that use the same name in 2 different counties of same state.
Examples
name2fips(c("de", "NY"))
#> query fullname fips fipstype
#> 1 de Delaware 10 state
#> 2 NY New York 36 state
#>
#>
#> [1] "10" "36"
name2fips("rhode island")
#> query fullname fips fipstype
#> 1 rhode island Rhode Island 44 state
#>
#>
#> [1] "44"
name2fips(c("delaware", "NY"))
#> query fullname fips fipstype
#> 1 delaware Delaware 10 state
#> 2 NY New York 36 state
#>
#>
#> [1] "10" "36"
name2fips(c("Magnolia town, DE", "Delaware City city, DE"))
#>
#> Exact match, or Cities/CDPs showing any multiple possible matches, etc. (excluding if no match):
#>
#> eparegion ST stfips countyname countyfips placename fips
#> 1 3 DE 10 Kent County 10001 Magnolia town 1044430
#> 2 3 DE 10 New Castle County 10003 Delaware City city 1019730
#> query multiple
#> 1 Magnolia town, DE
#> 2 Delaware City city, DE
#>
#>
#> query fullname fips fipstype
#> 1 Magnolia town, DE Magnolia town, DE 1044430 city
#> 2 Delaware City city, DE Delaware City city, DE 1019730 city
#>
#>
#> [1] "1044430" "1019730"
name2fips(c('denver', "new york" ), exact = F)
#> Warning: place_st should be in form of placename, ST like Port Chester, NY
#> query fullname fips fipstype
#> 1 denver <NA> <NA> <NA>
#> 2 new york New York 36 state
#>
#>
#> [1] NA "36"