Each US state and county has a unique FIPS (Federal Information Processing Standards) code. Use this function to obtain the FIPS code for a state or county.
Usage
fips(state, county = c())
Arguments
- state
The state(s) for which to obtain a FIPS code(s). Can be entered as either a state abbreviation or full name (case-insensitive).
state
can be entered as either a single state or a vector of states. Ifstate
is a vector,county
must be omitted.- county
The county for which to obtain a FIPS code. Can be entered with or without "county" (case-insensitive).
Value
The FIPS code(s) of given state
or county
.
If only states are entered, a vector of length equal to the number of states
is returned. If any states are not found or are invalid, NA
is returned in their place.
If a state and county are entered, a single value with the FIPS code for the given county is returned. If the county is invalid for the given state, an error is thrown.
If both state
and county
are omitted, the entire list of available FIPS
codes is returned, sorted by the state's abbreviation (e.g. Alaska (AK) comes
before Alabama (AL)).
Details
State and county FIPS (Federal Information Processing Standards) are two and five digit codes, respectively. They uniquely identify all states and counties within the United States. The first two digits of the five digit county codes correspond to the state that the county belongs to. FIPS codes also exist for US territories and minor outlying islands, though this package only provides information for the 50 US states (and their associated counties and census designated areas).
Note
A state
must be included when searching for county
,
otherwise multiple results may be returned for duplicate county names.
Examples
fips()
#> [1] "02" "01" "05" "04" "06" "08" "09" "11" "10" "12" "13" "15" "19" "16" "17"
#> [16] "18" "20" "21" "22" "25" "24" "23" "26" "27" "29" "28" "30" "31" "37" "33"
#> [31] "38" "34" "35" "32" "36" "39" "40" "41" "42" "44" "45" "46" "47" "48" "49"
#> [46] "51" "50" "53" "55" "54" "56"
fips("NJ")
#> [1] "34"
fips("California")
#> [1] "06"
fips(c("AK", "CA", "UT"))
#> [1] "02" "06" "49"
fips("CA", county = "orange")
#> [1] "06059"
fips(state = "AL", county = "autauga")
#> [1] "01001"
fips(state = "Alabama", county = "Autauga County")
#> [1] "01001"