View source: R/census_helper.R
census_helper | R Documentation |
census_helper
links user-input dataset with Census geographic data.
census_helper(
key = Sys.getenv("CENSUS_API_KEY"),
voter.file,
states = "all",
geo = "tract",
age = FALSE,
sex = FALSE,
year = "2020",
census.data = NULL,
retry = 3,
use.counties = FALSE
)
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? |
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.
Output will be an object of class data.frame
. It will
consist of the original user-input data with additional columns of
Census data.
## Not run:
census_helper(voter.file = voters, states = "nj", geo = "block")
## End(Not run)
## Not run:
census_helper(
voter.file = voters, states = "all", geo = "tract",
age = TRUE, sex = TRUE
)
## End(Not run)
## Not run:
census_helper(
voter.file = voters, states = "all", geo = "county",
age = FALSE, sex = FALSE, year = "2020"
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.