Package 'zctaCrosswalk'

Title: Crosswalk Between 2020 Census ZIP Code Tabulation Areas (ZCTAs), States and Counties
Description: Contains the US Census Bureau's 2020 ZCTA to County Relationship File, as well as convenience functions to translate between States, Counties and ZIP Code Tabulation Areas (ZCTAs).
Authors: Ari Lamstein [aut, cre], MarketBridge LLC [cph, fnd]
Maintainer: Ari Lamstein <[email protected]>
License: MIT + file LICENSE
Version: 2.0.0
Built: 2024-11-12 05:12:08 UTC
Source: https://github.com/marketbridge/zctacrosswalk

Help Index


Returns a ZCTA crosswalk as a tibble

Description

Returns the Census Bureau's 2020 ZCTA Country Relationship file as a tibble. This function is included so that users can see how the crosswalk was generated. It is not intended for use by end users.

Usage

get_zcta_crosswalk()

Value

A tibble, where each row is a (zcta, county, state) combination.

See Also

All 2020 ZIP Code Tabulation Area 5-Digit (ZCTA5) Relationship Files: https://rb.gy/h0l5cs


Return metadata on a ZCTA

Description

Given a vector of ZIP Code Tabulation Areas (ZCTAs), return what state and county they are in. NOTE: A single ZCTA can span multiple states and counties.

Usage

get_zcta_metadata(zctas)

Arguments

zctas

A vector of ZCTAs (character or numeric)

Value

A tibble, where each row is a (zcta, county, state) combination.

Examples

get_zcta_metadata("90210")

# Some ZCTAs span multiple counties
get_zcta_metadata(39573)

Return the ZCTAs in a vector of counties

Description

Given a vector of counties, return the ZIP Code Tabulation Areas (ZCTAs) in those counties. Note counties must be identified by FIPS code (character or numeric) in this function because county names are not unique between states. For example, 30 states have a county named "Washington".

Usage

get_zctas_by_county(counties)

Arguments

counties

A vector of Counties. Must be by FIPS code (numeric or character).

Value

A vector, where each element is a ZCTA in the requested county.

Examples

# "06075" is San Francisco County, California
get_zctas_by_county("06075")

# 6075 (== as.numeric("06075")) works too
get_zctas_by_county(6075)

# Multiple counties at the same time are also OK
get_zctas_by_county(c("06075", "36059"))

Return the ZCTAs in a vector of states

Description

Given a vector of states, return the ZIP Code Tabulation Areas (ZCTAs) in those states.

Usage

get_zctas_by_state(states)

Arguments

states

A vector of States. Can be FIPS Codes (either character or numeric), names or USPS abbreviations.

Value

A vector, where each element is a ZCTA in the requested state.

Examples

# Not case sensitive when using state names
ca_zctas = get_zctas_by_state("CaLiFoRNia")
length(ca_zctas)
head(ca_zctas)

# "06" is the FIPS code for California
ca_zctas = get_zctas_by_state("06")
length(ca_zctas)
head(ca_zctas)

# 6 is OK too - sometimes people use numbers for FIPS codes
ca_zctas = get_zctas_by_state(6)
length(ca_zctas)
head(ca_zctas)

# USPS state abbreviations are also OK
ca_zctas = get_zctas_by_state("CA")
length(ca_zctas)
head(ca_zctas)

# Multiple states at the same time are also OK
ca_ny_zctas = get_zctas_by_state(c("CA", "NY"))
length(ca_ny_zctas)
head(ca_ny_zctas)

Metadata for Each "State" in zcta_crosswalk

Description

The complete dataset in ?zcta_crosswalk contains information on 56 state and state-equivalents. This dataframe contains the full name of each "state", plus its USPS abbreviation and FIPS code.

Usage

data(state_names)

2020 Crosswalk of ZIP Code Tabulation Areas (ZCTAs)

Description

The primary data was obtained via the function get_zcta_crosswalk. There are 3 types of columns: ZCTA, state and county. Where data in practice sometimes appears as both character and numeric, columns for both are provided.

Usage

data(zcta_crosswalk)