-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathretrieve_ACS_data.Rmd
More file actions
39 lines (27 loc) · 897 Bytes
/
retrieve_ACS_data.Rmd
File metadata and controls
39 lines (27 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
---
title: "Retrieving American Survey Data"
author: "Tom"
date: "October 6, 2015"
output: html_document
---
### Code for Retrieving Data from the American Community Survey
Make sure to request a key from the Census website: http://api.census.gov/data/key_signup.html
```{r, eval = FALSE}
library(reshape2)
library(plyr)
library(dplyr)
library(acs)
Census_key <- # YOUR KEY. Get it from the Census API
api.key.install(key=Census.key)
# Make Your Geometry, Here I use all census tracts in Washngton DC
geo.DC <- geo.make(state = 11, county = 001, tract = "*")
# Function to get ACS Data
get_ACS_Data <- function(geometry, table){
acs_data <- acs.fetch(geo = geometry, table.number=table,
endyear = 2013, span = 5, col.names = "pretty" )
acs_data <- data.frame(estimate(acs_data))
return(acs_data)
}
# Write to file
write.csv(acs_data, "ACS_Data.csv")
```