-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDataCleanUp.R
220 lines (204 loc) · 8.38 KB
/
DataCleanUp.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# Dependencies
library(tidyverse)
### Loading Data ###
# Rental Data
# Rental Studio Inventory
RentalStudioInventory = read.csv("./rawData/F1_rentalInventory_Studio.csv", stringsAsFactors = FALSE) %>%
filter(.,
AreaType == "neighborhood",
Boro != "Bronx") %>%
gather(.,
key = "yearMonth",
value = "rentalStudioInventory",
X2010.01:X2018.08) %>%
mutate(.,
time = as.Date(paste(yearMonth, ".01", sep = ""), format = "X%Y.%m.%d")) %>%
filter(., time >= as.Date("2014-01-01")) %>%
select(., Area, Boro, time, rentalStudioInventory)
# Rental Studio Median Listing Price
RentalStudioMedianPrice = read.csv("./rawData/F2_medianAskingRent_Studio.csv", stringsAsFactors = FALSE) %>%
filter(.,
AreaType == "neighborhood",
Boro != "Bronx") %>%
gather(.,
key = "yearMonth",
value = "rentalStudioMedPrice",
X2010.01:X2018.08) %>%
mutate(.,
time = as.Date(paste(yearMonth, ".01", sep = ""), format = "X%Y.%m.%d")) %>%
filter(., time >= as.Date("2014-01-01")) %>%
select(., Area, Boro, time, rentalStudioMedPrice)
# Rental One Bedroom Inventory
RentalOneBdInventory = read.csv("./rawData/G1_rentalInventory_OneBd.csv", stringsAsFactors = FALSE) %>%
filter(.,
AreaType == "neighborhood",
Boro != "Bronx") %>%
gather(.,
key = "yearMonth",
value = "rentalOneBdInventory",
X2010.01:X2018.08) %>%
mutate(.,
time = as.Date(paste(yearMonth, ".01", sep = ""), format = "X%Y.%m.%d")) %>%
filter(., time >= as.Date("2014-01-01")) %>%
select(., Area, Boro, time, rentalOneBdInventory)
# Rental One Bedroom Median Listing Price
RentalOneBdMedianPrice = read.csv("./rawData/G2_medianAskingRent_OneBd.csv", stringsAsFactors = FALSE) %>%
filter(.,
AreaType == "neighborhood",
Boro != "Bronx") %>%
gather(.,
key = "yearMonth",
value = "rentalOneBdMedPrice",
X2010.01:X2018.08) %>%
mutate(.,
time = as.Date(paste(yearMonth, ".01", sep = ""), format = "X%Y.%m.%d")) %>%
filter(., time >= as.Date("2014-01-01")) %>%
select(., Area, Boro, time, rentalOneBdMedPrice)
# Rental Two Bedroom Inventory
RentalTwoBdInventory = read.csv("./rawData/H1_rentalInventory_TwoBd.csv", stringsAsFactors = FALSE) %>%
filter(.,
AreaType == "neighborhood",
Boro != "Bronx") %>%
gather(.,
key = "yearMonth",
value = "rentalTwoBdInventory",
X2010.01:X2018.08) %>%
mutate(.,
time = as.Date(paste(yearMonth, ".01", sep = ""), format = "X%Y.%m.%d")) %>%
filter(., time >= as.Date("2014-01-01")) %>%
select(., Area, Boro, time, rentalTwoBdInventory)
# Rental Two Bedroom Median Listing Price
RentalTwoBdMedianPrice = read.csv("./rawData/H2_medianAskingRent_TwoBd.csv", stringsAsFactors = FALSE) %>%
filter(.,
AreaType == "neighborhood",
Boro != "Bronx") %>%
gather(.,
key = "yearMonth",
value = "rentalTwoBdMedPrice",
X2010.01:X2018.08) %>%
mutate(.,
time = as.Date(paste(yearMonth, ".01", sep = ""), format = "X%Y.%m.%d")) %>%
filter(., time >= as.Date("2014-01-01")) %>%
select(., Area, Boro, time, rentalTwoBdMedPrice)
# Rental Three Bedroom Inventory
RentalThreeBdInventory = read.csv("./rawData/I1_rentalInventory_ThreePlusBd.csv", stringsAsFactors = FALSE) %>%
filter(.,
AreaType == "neighborhood",
Boro != "Bronx") %>%
gather(.,
key = "yearMonth",
value = "rentalThreeBdInventory",
X2010.01:X2018.08) %>%
mutate(.,
time = as.Date(paste(yearMonth, ".01", sep = ""), format = "X%Y.%m.%d")) %>%
filter(., time >= as.Date("2014-01-01")) %>%
select(., Area, Boro, time, rentalThreeBdInventory)
# Rental Three Bedroom Median Listing Price
RentalThreeBdMedianPrice = read.csv("./rawData/I2_medianAskingRent_ThreePlusBd.csv", stringsAsFactors = FALSE) %>%
filter(.,
AreaType == "neighborhood",
Boro != "Bronx") %>%
gather(.,
key = "yearMonth",
value = "rentalThreeBdMedPrice",
X2010.01:X2018.08) %>%
mutate(.,
time = as.Date(paste(yearMonth, ".01", sep = ""), format = "X%Y.%m.%d")) %>%
filter(., time >= as.Date("2014-01-01")) %>%
select(., Area, Boro, time, rentalThreeBdMedPrice)
# Sales Data
# Condo Inventory
CondoInventory = read.csv("./rawData/B1_totalInventory_Condo.csv", stringsAsFactors = FALSE) %>%
filter(.,
AreaType == "neighborhood",
Boro != "Bronx") %>%
gather(.,
key = "yearMonth",
value = "condoInventory",
X2010.01:X2018.08) %>%
mutate(.,
time = as.Date(paste(yearMonth, ".01", sep = ""), format = "X%Y.%m.%d")) %>%
filter(., time >= as.Date("2014-01-01")) %>%
select(., Area, Boro, time, condoInventory)
# Condo Median Asking Price
CondoMedAskPrice = read.csv("./rawData/B3_medianAskingPrice_Condo.csv", stringsAsFactors = FALSE) %>%
filter(.,
AreaType == "neighborhood",
Boro != "Bronx") %>%
gather(.,
key = "yearMonth",
value = "condoMedAskPrice",
X2010.01:X2018.08) %>%
mutate(.,
time = as.Date(paste(yearMonth, ".01", sep = ""), format = "X%Y.%m.%d")) %>%
filter(., time >= as.Date("2014-01-01")) %>%
select(., Area, Boro, time, condoMedAskPrice)
# Condo Median Sale Price
CondoMedSalePrice = read.csv("./rawData/B6_medianSalePrice_Condo.csv", stringsAsFactors = FALSE) %>%
filter(.,
AreaType == "neighborhood",
Boro != "Bronx") %>%
gather(.,
key = "yearMonth",
value = "condoMedSalePrice",
X2010.01:X2018.08) %>%
mutate(.,
time = as.Date(paste(yearMonth, ".01", sep = ""), format = "X%Y.%m.%d")) %>%
filter(., time >= as.Date("2014-01-01")) %>%
select(., Area, Boro, time, condoMedSalePrice)
# Single Family Inventory
SFInventory = read.csv("./rawData/D1_totalInventory_Sfr.csv", stringsAsFactors = FALSE) %>%
filter(.,
AreaType == "neighborhood",
Boro != "Bronx") %>%
gather(.,
key = "yearMonth",
value = "sfInventory",
X2010.01:X2018.08) %>%
mutate(.,
time = as.Date(paste(yearMonth, ".01", sep = ""), format = "X%Y.%m.%d")) %>%
filter(., time >= as.Date("2014-01-01")) %>%
select(., Area, Boro, time, sfInventory)
# Single Family Median Asking Price
SFMedAskPrice = read.csv("./rawData/D3_medianAskingPrice_Sfr.csv", stringsAsFactors = FALSE) %>%
filter(.,
AreaType == "neighborhood",
Boro != "Bronx") %>%
gather(.,
key = "yearMonth",
value = "sfMedAskPrice",
X2010.01:X2018.08) %>%
mutate(.,
time = as.Date(paste(yearMonth, ".01", sep = ""), format = "X%Y.%m.%d")) %>%
filter(., time >= as.Date("2014-01-01")) %>%
select(., Area, Boro, time, sfMedAskPrice)
# Single Family Median Sale Price
SFMedSalePrice = read.csv("./rawData/D6_medianSalePrice_Sfr.csv", stringsAsFactors = FALSE) %>%
filter(.,
AreaType == "neighborhood",
Boro != "Bronx") %>%
gather(.,
key = "yearMonth",
value = "sfMedSalePrice",
X2010.01:X2018.08) %>%
mutate(.,
time = as.Date(paste(yearMonth, ".01", sep = ""), format = "X%Y.%m.%d")) %>%
filter(., time >= as.Date("2014-01-01")) %>%
select(., Area, Boro, time, sfMedSalePrice)
### Combined Data ###
StreetEasyCombined = RentalStudioInventory %>%
left_join(., RentalStudioMedianPrice, by = c("Boro", "Area", "time")) %>%
left_join(., RentalOneBdInventory, by = c("Boro", "Area", "time")) %>%
left_join(., RentalOneBdMedianPrice, by = c("Boro", "Area", "time")) %>%
left_join(., RentalTwoBdInventory, by = c("Boro", "Area", "time")) %>%
left_join(., RentalTwoBdMedianPrice, by = c("Boro", "Area", "time")) %>%
left_join(., RentalThreeBdInventory, by = c("Boro", "Area", "time")) %>%
left_join(., RentalThreeBdMedianPrice, by = c("Boro", "Area", "time")) %>%
left_join(., CondoInventory, by = c("Boro", "Area", "time")) %>%
left_join(., CondoMedAskPrice, by = c("Boro", "Area", "time")) %>%
left_join(., CondoMedSalePrice, by = c("Boro", "Area", "time")) %>%
left_join(., SFInventory, by = c("Boro", "Area", "time")) %>%
left_join(., SFMedAskPrice, by = c("Boro", "Area", "time")) %>%
left_join(., SFMedSalePrice, by = c("Boro", "Area", "time"))
### Write to File for backup ###
write.csv(StreetEasyCombined, file = "StreetEasyCombined.csv", row.names=FALSE)