-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCode_Data_Collect.R
60 lines (40 loc) · 1.97 KB
/
Code_Data_Collect.R
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# PERSON FILES - Download, Unzip, Consolidate, and Save -------------------
#Create temp file to store downloaded zip file
temp <- tempfile()
#Download Person file for Puerto Rico
download.file(url = "https://www2.census.gov/programs-surveys/acs/data/pums/2015/1-Year/csv_ppr.zip", destfile = temp)
#unzip Person File Puerto Rico
ppr15 <- read.csv(unzip(zipfile = temp, files = c("ss15ppr.csv"), exdir = "./Data"))
#Download Person file for US
download.file(url = "https://www2.census.gov/programs-surveys/acs/data/pums/2015/1-Year/csv_pus.zip", destfile = temp)
#unzip Person US A & B Files
pusa15 <-read.csv(unzip(zipfile = temp, files = c("ss15pusa.csv"), exdir = "./Data"))
pusb15 <-read.csv(unzip(zipfile = temp, files = c("ss15pusb.csv"), exdir = "./Data"))
#Combine all Person files
pusab15 <- rbind(pusa15, pusb15, ppr15)
#clear workspace
rm(pusa15, pusb15, ppr15, temp)
#Save consolidated Person files as *.Rds
saveRDS(pusab15, "./Data/pusab15.rds")
#rm Person data frame
rm(pusab15)
# HOUSING FILES - Download, Unzip, Consolidate, and Save ------------------
#Create temp file to store downloaded zip file
temp <- tempfile()
#Download HOUSING file for Puerto Rico
download.file(url = "https://www2.census.gov/programs-surveys/acs/data/pums/2015/1-Year/csv_hpr.zip", destfile = temp)
#unzip HOUSING File Puerto Rico
hpr15 <- read.csv(unzip(zipfile = temp, files = c("ss15hpr.csv"), exdir = "./Data"))
#Download HOUSING file for US
download.file(url = "https://www2.census.gov/programs-surveys/acs/data/pums/2015/1-Year/csv_hus.zip", destfile = temp)
#unzip HOUSING US A & B Files
husa15 <-read.csv(unzip(zipfile = temp, files = c("ss15husa.csv"), exdir = "./Data"))
husb15 <-read.csv(unzip(zipfile = temp, files = c("ss15husb.csv"), exdir = "./Data"))
#Combine all Person files
husab15 <- rbind(husa15, husb15, hpr15)
#clear workspace
rm(husa15, husb15, hpr15, temp)
#Save consolidated Person files as *.Rds
saveRDS(husab15, "./Data/husab15.rds")
#rm HOUSING data frame
rm(husab15)