March 2, 2016
Save this email!
APIs are sets of requirements that govern how one application can talk to another - readwrite.com
http://api.census.gov/data/2014/acs5?get=NAME,B01001_001E,B19013_001E&for=county:*
R can do everything for you besides reading the documentation
(But some functions can help with that)
install.packages("devtools")
devtools::install_github("hrecht/censusapi")
# Load the library
library("censusapi")
1. name
"acs5"
2. vintage - required for all datasets besides time series
2014
3. key
string emailed by Census
4. vars
c("NAME", "B01001_001E", "B19013_001E", "B17010_017E", "B17010_037E")
5. region
"county:*"
apis <- listCensusApis()
View(apis)
vars2014 <- listCensusMetadata(name="acs5", vintage=2014, "v")
View(vars2014)
geos2014 <- listCensusMetadata(name="acs5", vintage=2014, "g")
View(geos2014)
data2014 <- getCensus(name="acs5",
vintage=2014,
key=censuskey,
vars=c("NAME", "B01001_001E", "B19013_001E",
"B17010_017E", "B17010_037E"),
region="county:*")
View(data2014)
data2000 <- getCensus(name="sf3", vintage=2000,
key=censuskey,
vars=c("P001001", "P053001", "H063001"),
region="county:*", regionin="state:06")
tracts <- NULL
# For all states in the fips list
for (f in fips) {
# Define what state to get
stateget <- paste("state:", f, sep="")
# Get data for all tracts within that state
temp <- getCensus(name="acs5", vintage=2014,
key=censuskey,
vars=c("B01001_001E", "B19013_001E", "B17010_017E", "B17010_037E"),
region="tract:*", regionin=stateget)
# Bind to existing data
tracts <- rbind(tracts, temp)
}
View(tracts)
Especially useful for tracts and blocks - can only get one state at a time