census_helper_new {wru} | R Documentation |
Census helper function.
Description
census_helper_new
links user-input dataset with Census geographic data.
Usage
census_helper_new(
key = Sys.getenv("CENSUS_API_KEY"),
voter.file,
states = "all",
geo = c("tract", "block", "block_group", "county", "place", "zcta"),
age = FALSE,
sex = FALSE,
year = "2020",
census.data = NULL,
retry = 3,
use.counties = FALSE,
skip_bad_geos = FALSE
)
Arguments
key |
A character string containing a valid Census API key, which can be requested from the U.S. Census API key signup page. By default, attempts to find a census key stored in an
environment variable named |
voter.file |
An object of class |
states |
A character vector specifying which states to extract
Census data for, e.g. |
geo |
A character object specifying what aggregation level to use.
Use |
age |
A |
sex |
A |
year |
A character object specifying the year of U.S. Census data to be downloaded.
Use |
census.data |
A optional census object of class |
retry |
The number of retries at the census website if network interruption occurs. |
use.counties |
A logical, defaulting to FALSE. Should census data be filtered by counties available in census.data? |
skip_bad_geos |
Logical. Option to have the function skip any geolocations that are not present
in the census data, returning a partial data set. Default is set to |
Details
This function allows users to link their geocoded dataset (e.g., voter file) with U.S. Census data (2010 or 2020). The function extracts Census Summary File data at the county, tract, block, or place level. Census data calculated are Pr(Geolocation | Race) where geolocation is county, tract, block, or place.
Value
Output will be an object of class data.frame
. It will
consist of the original user-input data with additional columns of
Census data.
Examples
## Not run: census_helper_new(voter.file = voters, states = "nj", geo = "block")
## Not run: census_helper_new(voter.file = voters, states = "all", geo = "tract")
## Not run: census_helper_new(voter.file = voters, states = "all", geo = "place",
year = "2020")
## End(Not run)