Learn R Programming

zippeR (version 0.1.0)

zi_get_demographics: Download Demographic Data for Five-digit ZCTAs

Description

This function returns demographic data for five-digit ZIP Code Tabulation Areas (ZCTAs), which are rough approximations of many (but not all) USPS ZIP codes.

Usage

zi_get_demographics(year, variables = NULL, table = NULL,
    survey, output = "tidy", zcta = NULL, key = NULL)

Value

A tibble containing all demographic data requested in either

"tidy" or "wide" format.

Arguments

year

A four-digit numeric scalar for year. zippeR currently supports data for from 2010 to 2022. Different survey products are available for different years. See the survey parameter for more details

variables

A character scalar or vector of variable IDs.

table

A character scalar of a table ID (only one table may be requested per call).

survey

A character scalar representing the Census product. It can be either a Decennial Census product (either "sf1" or "sf3") or an American Community Survey product (either "acs1", "acs3", or "acs5"). For Decennial Census calls, only the 2010 Census is available. In addition, if a variable cannot be found in "sf1", the function will look in "sf3". Also note that "acs3" was discontinued after 2013.

output

A character scalar; one of "tidy" (long output) or "wide" depending on the type of data format you want. If you are planning to pass these data to zi_aggregate(), you must choose "tidy". If you are leaving these data as five-digit ZCTAs and are planning to join them with geometric data, "wide" is the strongly encouraged format.

zcta

An optional vector of ZCTAs that demographic data are requested for. If this is NULL, data will be returned for all ZCTAs. If a vector is supplied, only data for those requested ZCTAs will be returned. The vector can be created with zi_get_geometry() and should only contain five-digit ZCTAs.

key

A Census API key, which can be obtained at https://api.census.gov/data/key_signup.html. This can be omitted if tidycensus::census_api_key() has been used to write your key to your .Renviron file. You can check whether an API key has been written to .Renviron by using Sys.getenv("CENSUS_API_KEY").

Examples

Run this code
# \donttest{
  # download all ZCTAs
  zi_get_demographics(year = 2012, variables = "B01003_001", survey = "acs5")

  # limit output to subset of ZCTAs
  ## download all ZCTAs in Missouri, intersects method
  mo20 <- zi_get_geometry(year = 2020, state = "MO", method = "intersect")

  ## download demographic data
  zi_get_demographics(year = 2012, variables = "B01003_001", survey = "acs5",
      zcta = mo20$GEOID)
# }

Run the code above in your browser using DataLab