fips: Retrieve FIPS code for either a US state or county

View source: R/fips.R

fipsR Documentation

Retrieve FIPS code for either a US state or county

Description

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. If state 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).

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).

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)).

Note

A state must be included when searching for county, otherwise multiple results may be returned for duplicate county names.

See Also

fips_info()

Examples

fips()

fips("NJ")
fips("California")

fips(c("AK", "CA", "UT"))

fips("CA", county = "orange")
fips(state = "AL", county = "autauga")
fips(state = "Alabama", county = "Autauga County")

usmap documentation built on May 29, 2024, 10:26 a.m.