-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMissing.R
186 lines (159 loc) · 8.06 KB
/
Missing.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
library(tidyverse)
years <- c(1991,1993,1996,1999,2002,2005,2008,2011,2014,2017)
dta <- list()
for (i in 1:10) {
name <- str_c("DATA/NYCHVS ", years[i]," Occupied File for ASA Challenge.csv")
dta[[i]] <- read_csv(name, skip = 1)
}
NYC <- dta[[1]]
for (i in 2:3) {
dta[[i]] %>%
bind_rows(NYC) ->
NYC
}
for (i in 4:9) {
dta[[i]] %>% dplyr::select(-`Floor of unit`) %>%
bind_rows(NYC) ->
NYC
}
dta[[10]] %>%
bind_rows(NYC) ->
NYC
NYC %>% select(`Toilet breakdowns`) %>% summarise(missing = sum(`Toilet breakdowns` == 8), total = n(), pct_missing = missing/total)
NYC %>% select(`Heating equipment breakdown`) %>% summarise(missing = sum(`Heating equipment breakdown` == 8), total = n(), pct_missing = missing/total)
names(NYC)
NYC %>% select(`Out of pocket rent`) %>% summarise(missing = sum(`Out of pocket rent` == 99998), total = n(), pct_mising = missing/total)
NYC %>% select(`Out of pocket rent`) %>% View()
NYC %>% select(`Out of pocket rent`, `Year Identifier`) %>% group_by(`Year Identifier`) %>% summarise(missing = sum(is.na(`Out of pocket rent`)))
NYC %>% dplyr::filter(starts_with("Y"))
names(dta[[10]]) -> nms
vars_select(nms, starts_with("Floor"))
nms <- names(NYC)
vars_select(nms, starts_with("Y"))
NYC %>% count(`Year Identifier`)
NYC %>% select(`Toilet breakdowns`, `Year Identifier`) %>% group_by(`Year Identifier`) %>%
summarise(missing = sum(`Toilet breakdowns` == 8),
total = n(), missing_pct = missing/total)
NYC %>% select(`Heating equipment breakdown`, `Year Identifier`) %>% group_by(`Year Identifier`) %>%
summarise(missing = sum(`Heating equipment breakdown` == 8),
total = n(), missing_pct = missing/total)
NYC %>% select(`Out of pocket rent`, `Year Identifier`) %>% group_by(`Year Identifier`) %>% summarise(missing = sum(is.na(`Out of pocket rent`)))
NYC %>% select(`Monthly contract rent`, `Year Identifier`) %>% group_by(`Year Identifier`) %>% summarise(missing = sum(is.na(`Monthly contract rent`)))
NYC %>% select(`Monthly contract rent`, `Year Identifier`) %>% group_by(`Year Identifier`) %>% summarise(missing = sum(`Monthly contract rent` == 99999),
total = n(),
missing_pct = missing/total)
NYC <- NYC %>% mutate(waterleakage = ifelse(`Year Identifier` > 2000,
`Water leakage inside apartment`,
`Water leakage inside apartment (house)`))
NYC %>% filter(`Tenure 1` == 1) -> Owned
NYC %>% filter(`Tenure 1` == 9) -> Rented
## Rented ####################################################################
# A lot of toilet missing in 2008
Rented %>% select(`Toilet breakdowns`, `Year Identifier`) %>% group_by(`Year Identifier`) %>%
summarise(missing = sum(`Toilet breakdowns` == 8),
total = n(), missing_pct = missing/total)
# A lot of heating missing in 2008
Rented %>% select(`Heating equipment breakdown`, `Year Identifier`) %>% group_by(`Year Identifier`) %>%
summarise(missing = sum(`Heating equipment breakdown` == 8),
total = n(), missing_pct = missing/total)
# Very little missing for monthly contract rent
Rented %>% select(`Monthly contract rent`, `Year Identifier`) %>%
group_by(`Year Identifier`) %>%
summarise(missing = sum(`Monthly contract rent` == 99999),
total = n(),
missing_pct = missing/total)
# No missing plumbing
Rented %>% select(`Complete plumbing facilities`, `Year Identifier`) %>%
group_by(`Year Identifier`) %>%
summarise(missing = sum(is.na(`Complete plumbing facilities`)),
total = n(),
missing_pct = missing/total)
# A lot of missing kitchen in 2008
Rented %>% select(`Kitchen facilities functioning`, `Year Identifier`) %>%
group_by(`Year Identifier`) %>%
summarise(missing = sum(`Kitchen facilities functioning` == 8),
total = n(),
missing_pct = missing/total)
# A lot of missing water leakage in 2008
Rented %>% select(waterleakage, `Year Identifier`) %>%
group_by(`Year Identifier`) %>%
summarise(missing = sum(waterleakage == 8),
total = n(),
missing_pct = missing/total)
# No missing number of rooms
Rented %>% select(`Number of rooms`, `Year Identifier`) %>%
group_by(`Year Identifier`) %>%
summarise(missing = sum(is.na(`Number of rooms`)),
total = n(),
missing_pct = missing/total)
# No missing number of bedrooms
Rented %>% select(`Number of bedrooms`, `Year Identifier`) %>%
group_by(`Year Identifier`) %>%
summarise(missing = sum(is.na(`Number of bedrooms`)),
total = n(),
missing_pct = missing/total)
# No missing condition of building
Rented %>% select(`Condition of building`, `Year Identifier`) %>%
group_by(`Year Identifier`) %>%
summarise(missing = sum(`Condition of building` == 8),
total = n(),
missing_pct = missing/total)
# Floor conditions missing at really high rates
Rented %>% select(`Condition of floors: Sagging or sloping floors`, `Condition of floors: Sagging/sloping floors OR slanted/shifted doorsills/frames`, `Year Identifier`) %>%
group_by(`Year Identifier`) %>%
summarise(missing = sum(`Condition of floors: Sagging or sloping floors` == 8 |
`Condition of floors: Sagging or sloping floors` == 9),
missing2 = sum(`Condition of floors: Sagging/sloping floors OR slanted/shifted doorsills/frames` == 8 |
`Condition of floors: Sagging/sloping floors OR slanted/shifted doorsills/frames` == 9),
total = n(), misssing_pct = missing/total, missing_pct2 = missing2/total)
## Owned #########################################################
# A lot of toilet missing in 2008
Owned %>% select(`Toilet breakdowns`, `Year Identifier`) %>% group_by(`Year Identifier`) %>%
summarise(missing = sum(`Toilet breakdowns` == 8),
total = n(), missing_pct = missing/total)
# A lot of missing in 2008
Owned %>% select(`Heating equipment breakdown`, `Year Identifier`) %>% group_by(`Year Identifier`) %>%
summarise(missing = sum(`Heating equipment breakdown` == 8),
total = n(), missing_pct = missing/total)
# Only missing value in 1991
Owned %>% select(Value, `Year Identifier`) %>%
group_by(`Year Identifier`) %>%
summarise(missing = sum(Value == 9999998 | Value == 9999999),
total = n(),
missing_pct = missing/total)
# No missing plumbing
Owned %>% select(`Complete plumbing facilities`, `Year Identifier`) %>%
group_by(`Year Identifier`) %>%
summarise(missing = sum(is.na(`Complete plumbing facilities`)),
total = n(),
missing_pct = missing/total)
# A lot of missing kitchen in 2008
Owned %>% select(`Kitchen facilities functioning`, `Year Identifier`) %>%
group_by(`Year Identifier`) %>%
summarise(missing = sum(`Kitchen facilities functioning` == 8),
total = n(),
missing_pct = missing/total)
# A lot of water leakage missing in 2008
Owned %>% select(waterleakage, `Year Identifier`) %>%
group_by(`Year Identifier`) %>%
summarise(missing = sum(waterleakage == 8),
total = n(),
missing_pct = missing/total)
# No missing number of rooms
Owned %>% select(`Number of rooms`, `Year Identifier`) %>%
group_by(`Year Identifier`) %>%
summarise(missing = sum(is.na(`Number of rooms`)),
total = n(),
missing_pct = missing/total)
# No missing number of bedrooms
Owned %>% select(`Number of bedrooms`, `Year Identifier`) %>%
group_by(`Year Identifier`) %>%
summarise(missing = sum(is.na(`Number of bedrooms`)),
total = n(),
missing_pct = missing/total)
# No missing condition of building
Owned %>% select(`Condition of building`, `Year Identifier`) %>%
group_by(`Year Identifier`) %>%
summarise(missing = sum(`Condition of building` == 8),
total = n(),
missing_pct = missing/total)