Learn R Programming

wru (version 0.0-2)

census.helper.api: Census helper function.

Description

census.helper.api links user-input dataset with Census data.

Usage

census.helper.api(key, voters, states = "all", geo = "tract", demo = FALSE)

Arguments

key
A required character object. Must contain user's Census API key, which can be requested here.
voters
An object of class data.frame. Must contain field(s) named county, tract, and/or block that specifies geolocation.
states
A character vector specifying which states to extract Census data for, e.g. c("NJ", "NY"). Default is "all", which extracts Census data for all states contained in user-input data.
geo
A character object specifying what aggregation level to use. Use "county", "tract", or "block". Default is "tract". Warning: extracting block-level data takes very long.
demo
A TRUE/FALSE object indicating whether to condition on demographics (i.e., age and sex) or not. If TRUE, function will return Pr(Geolocation, Age, Sex | Race). If FALSE, function wil return Pr(Geolocation | Race). Default is FALSE.

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.

Details

This function allows users to link their geocoded dataset (e.g., voter file) with U.S. Census 2010 data. The function extracts Census Summary File data at the tract or block level using the 'UScensus2010' package. Census data calculated are Pr(Geolocation | Race) where geolocation is tract or block.

References

Relies on getCensusApi, getCensusApi2, and vecToChunk functions authored by Nicholas Nagle, available here.

Examples

Run this code

## Not run: census.helper.api(key = "...", voters = voters, states = "nj", geo = "block")
## Not run: census.helper.api(key = "...", voters = voters, states = "all", geo = "tract", 
# demo = TRUE)## End(Not run)

Run the code above in your browser using DataLab