census.helper.api: Census helper function.

Description Usage Arguments Details Value References Examples

View source: R/census.helper.api.R

Description

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

Usage

1
2
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.

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.

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.

References

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

Examples

1
2
3
4
## 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)

HJ08003/HJwru documentation built on May 6, 2019, 9:47 p.m.