zi_aggregate {zippeR} | R Documentation |
Aggregate ZCTAs to Three-digit ZCTAs
Description
This function takes input ZCTA data and aggregates it to three-digit areas, which are considerably larger. These regions are sometimes used in American health care contexts for publishing geographic identifiers.
Usage
zi_aggregate(.data, year, extensive = NULL, intensive = NULL,
intensive_method = "mean", survey, output = "tidy", zcta = NULL,
key = NULL)
Arguments
.data |
A tidy set of demographic data containing one or more variables that should be aggregated to three-digit ZCTAs. This data frame or tibble should contain all five-digit ZCTAs within the three digit ZCTAs that you plan to use for aggregating data. See Details below for formatting requirements. |
year |
A four-digit numeric scalar for year. |
extensive |
A character scalar or vector listing all extensive (i.e. count data) variables you wish to aggregate. These will be summed. For American Community Survey data, the margin of error will be calculated by taking the square root of the summed, squared margins of error for each five-digit ZCTA within a given three-digit ZCTA. |
intensive |
A character scalar or vector listing all intensive (i.e.
ratio, percent, or median data) variables you wish to aggregate. These
will be combined using the approach listed for |
intensive_method |
A character scalar; either |
survey |
A character scalar representing the Census product. It can
be either a Decennial Census product (either |
output |
A character scalar; one of |
zcta |
An optional vector of ZCTAs that demographic data are requested
for. If this is |
key |
A Census API key, which can be obtained at
https://api.census.gov/data/key_signup.html. This can be omitted if
|
Value
A tibble containing all aggregated data requested in either
"tidy"
or "wide"
format.
Examples
# load sample demographic data
mo22_demos <- zi_mo_pop
# the above data can be replicated with the following code:
# zi_get_demographics(year = 2022, variables = c("B01003_001", "B19013_001"),
# survey = "acs5")
# load sample geometric data
mo22_zcta3 <- zi_mo_zcta3
# the above data can be replicated with the following code:
# zi_get_geometry(year = 2022, style = "zcta3", state = "MO",
# method = "intersect")
# aggregate a single variable
zi_aggregate(mo22_demos, year = 2020, extensive = "B01003_001", survey = "acs5",
zcta = mo22_zcta3$ZCTA3)
# aggregate multiple variables, outputting wide data
zi_aggregate(mo22_demos, year = 2020,
extensive = "B01003_001", intensive = "B19013_001", survey = "acs5",
zcta = mo22_zcta3$ZCTA3, output = "wide")