Dear list, I've gotten access to the US Census Bureau's developer API for accessing various datasets they maintain. Here is the link: http://www.census.gov/developers/ They say that: "Data are accessible to software developers through a stateless HTTP GET request. Up to 50 variables can be requested with a single API call. " I can successfully query the API in a web browser, for instance: http://api.census.gov/data/2010/sf1?key=mykey&get=P0010001,NAME&for=county:*&in=state:48 which returns the population total for each county in the state of Texas. The API returns the requested data in this structure: [["P0030001","NAME","state","county"], ["58458","Anderson County","48","001"], ["14786","Andrews County","48","003"], ["86771","Angelina County","48","005"], ["23158","Aransas County","48","007"], ["9054","Archer County","48","009"], ["1901","Armstrong County","48","011"], ["44911","Atascosa County","48","013"], ["28417","Austin County","48","015"]] So my question is, how can I perform this query in R, using these types of queries? Any thoughts would be most welcome. Thanks Corey ----- Corey Sparks, PhD Assistant Professor Department of Demography University of Texas at San Antonio 501 West C?sar E. Ch?vez Blvd Monterey Building 2.270C San Antonio, TX 78207 210-458-3166 corey.sparks 'at' utsa.edu https://rowdyspace.utsa.edu/users/ozd504/www/index.htm -- View this message in context: http://r.789695.n4.nabble.com/Reading-data-from-Census-API-into-R-tp4684877.html Sent from the R help mailing list archive at Nabble.com.
Reading data from Census API into R
2 messages · Corey Sparks
I got it:
library(rjson)
library(plyr)
test<-fromJSON(file=url("http://api.census.gov/data/2010/sf1?key=mykey&get=P0030001,NAME&for=county:*&in=state:48"))
test2<-ldply(test)[-1,]
names(test2)<-ldply(test)[1,]
head(test2)
P0030001 NAME state county
2 58458 Anderson County 48 001
3 14786 Andrews County 48 003
4 86771 Angelina County 48 005
5 23158 Aransas County 48 007
6 9054 Archer County 48 009
7 1901 Armstrong County 48 011
-----
Corey Sparks, PhD
Assistant Professor
Department of Demography
University of Texas at San Antonio
501 West C?sar E. Ch?vez Blvd
Monterey Building 2.270C
San Antonio, TX 78207
210-458-3166
corey.sparks 'at' utsa.edu
coreysparks.weebly.com
--
View this message in context: http://r.789695.n4.nabble.com/Reading-data-from-Census-API-into-R-tp4684877p4684881.html
Sent from the R help mailing list archive at Nabble.com.