Skip to content

Instantly share code, notes, and snippets.

@jhollist
Last active December 31, 2015 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhollist/7948046 to your computer and use it in GitHub Desktop.
Save jhollist/7948046 to your computer and use it in GitHub Desktop.
Example using census api

Example using R and the Census API to get pop for all 50 states

First step is to install httr

install.packages("httr")
library(httr)

Next step is to activate an API key with the census. Just go here and follow the directions.

Once that is done the following should get your data into R. Be sure to put your active API key in the URL.

myURL<-"http://api.census.gov/data/2010/sf1?key=YOUR_API_KEY_HERE&get=P0010001,NAME&for=state:*"
x<-content(GET(myURL))
xdf<-data.frame(do.call("rbind",x[-1]))
names(xdf)<-x[[1]]
xdf

Trick to get other data out of census is to dig into the Census API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment