-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject.R
186 lines (124 loc) · 8.38 KB
/
Project.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
X919_data <- read_excel("919report_data.xlsx")
summary(X919_data)
#Case # Date Time Involved
#Min. : 1.00 Length:161 Length:161 Length:161
#1st Qu.: 7.00 Class :character Class :character Class :character
#Median : 21.00 Mode :character Mode :character Mode :character
#Mean : 52.43
#3rd Qu.:117.00
#Max. :188.00
#Name/Description Gender Height
#Length:161 Length:161 Length:161
#Class :character Class :character Class :character
#Mode :character Mode :character Mode :character
#Weight (lbs) Hair Colour Emergency Services Required
#Length:161 Length:161 Length:161
#Class :character Class :character Class :character
#Mode :character Mode :character Mode :character
#Call initiated to: Police (911) Call initiated to: Ambulance (911)
#Length:161 Length:161
#Class :character Class :character
#Mode :character Mode :character
#Call initiated to: Fire (911) Attended By: Police Attended By: Ambulance
#Length:161 Length:161 Length:161
#Class :character Class :character Class :character
#Mode :character Mode :character Mode :character
#Attended By:Fire Vehicle ID Incident Teyp(S): Medical
#Length:161 Length:161 Length:161
#Class :character Class :character Class :character
#Mode :character Mode :character Mode :character
#Incident Teyp(S): Injury Incident Teyp(S): Drug/Alcohol
#Length:161 Length:161
#Class :character Class :character
#Mode :character Mode :character
#Incident Teyp(S): Violence Incident Teyp(S): Staff Abuse
#Length:161 Length:161
#Class :character Class :character
#Mode :character Mode :character
#Incident Teyp(S): Refuse to leave Incident Teyp(S): Property Damage
#Length:161 Length:161
#Class :character Class :character
#Mode :character Mode :character
#Incident Teyp(S): Other (Type) First Aid required Overdose
#Length:161 Length:161 Length:161
#Class :character Class :character Class :character
#Mode :character Mode :character Mode :character
#Naloxone Event Location: Drop In Event Location: Lobby
#Length:161 Length:161 Length:161
#Class :character Class :character Class :character
#Mode :character Mode :character Mode :character
#Event Location: Courtyard Event Location: Kitchen
#Length:161 Length:161
#Class :character Class :character
#Mode :character Mode :character
#Event Location: Dinning Area Event Location: Chapel
#Length:161 Length:161
#Class :character Class :character
#Mode :character Mode :character
#Event Location: Hygiene Event Location: Games room
#Length:161 Length:161
#Class :character Class :character
#Mode :character Mode :character
#Event Location: Shipping&Reveiving Area
#Length:161
#Class :character
#Mode :character
#Event Location: Common Housing Area Event Location: In Room
#Length:161 Length:161
#Class :character Class :character
#Mode :character Mode :character
#Event Location: Perimeter Event Location:Snack Bar Other: (Enter)
#Length:161 Length:161 Length:161
#Class :character Class :character Class :character
#Mode :character Mode :character Mode :character
timing_cat <- c("Dawn", "Morning", "Noon", "Afternoon", "Evening", "Night")
# Dawn -> 12:01 am to 4:00 am 0.00069444444444444 to 0.16666666666666667
# Morning -> 4:01 am to 8:00 am 0.16736111111111111 to 0.33333333333333333
# Noon -> 8:01 am to 12:00 pm 0.33402777777777778 to 0.5
# Afternoon -> 12:01 pm to 4:00 pm 0.50069444444444444 to 0.66666666666666667
# Evening -> 4:01 pm to 8:00 pm 0.66736111111111111 to 0.83333333333333333
# Night -> 8:01 pm to 12:00 am 0.83402777777777778 to 1
time_vector <- X919_data$Time
len <- length(time_vector)
char_time <- vector(mode = "character", length = len) # create an empty vector
for(i in 1:len){
if(time_vector[i] > 0 && time_vector[i] <= 0.16666666666666667){
char_time[i] = "Dawn"
} else if(time_vector[i] > 0.16666666666666667 && time_vector[i] <= 0.33333333333333333){
char_time[i] = "Morning"
} else if(time_vector[i] > 0.33333333333333333 && time_vector[i] <= 0.5){
char_time[i] = "Noon"
} else if(time_vector[i] > 0.5 && time_vector[i] <= 0.66666666666666667){
char_time[i] = "Afternoon"
} else if(time_vector[i] > 0.66666666666666667 && time_vector[i] <= 0.83333333333333333){
char_time[i] = "Evening"
} else{
char_time[i] = "Night"
}
}
char_time
#[1] "Afternoon" "Night" "Noon" "Noon" "Noon" "Noon" "Afternoon" "Afternoon" "Afternoon" "Evening" "Evening" "Morning" "Morning" "Noon" "Noon"
#[16] "Night" "Afternoon" "Dawn" "Evening" "Night" "Night" "Evening" "Night" "Night" "Morning" "Afternoon" "Afternoon" "Night" "Evening" "Evening"
#[31] "Evening" "Evening" "Night" "Afternoon" "Afternoon" "Night" "Noon" "Afternoon" "Evening" "Evening" "Evening" "Dawn" "Afternoon" "Evening" "Evening"
#[46] "Afternoon" "Afternoon" "Night" "Noon" "Noon" "Afternoon" "Afternoon" "Evening" "Morning" "Noon" "Noon" "Noon" "Afternoon" "Night" "Noon"
#[61] "Noon" "Night" "Dawn" "Noon" "Noon" "Afternoon" "Afternoon" "Afternoon" "Noon" "Afternoon" "Evening" "Dawn" "Noon" "Night" "Dawn"
#[76] "Evening" "Night" "Night" "Noon" "Noon" "Noon" "Noon" "Night" "Afternoon" "Noon" "Afternoon" "Afternoon" "Afternoon" "Night" "Afternoon"
#[91] "Evening" "Evening" "Noon" "Noon" "Noon" "Afternoon" "Afternoon" "Evening" "Evening" "Noon" "Noon" "Afternoon" "Noon" "Night" "Noon"
#[106] "Afternoon" "Evening" "Noon" "Afternoon" "Evening" "Evening" "Evening" "Evening" "Noon" "Afternoon" "Dawn" "Evening" "Evening" "Evening" "Afternoon"
#[121] "Afternoon" "Evening" "Evening" "Noon" "Noon" "Afternoon" "Afternoon" "Afternoon" "Afternoon" "Night" "Afternoon" "Afternoon" "Evening" "Morning" "Afternoon"
#[136] "Evening" "Evening" "Night" "Noon" "Afternoon" "Evening" "Evening" "Evening" "Evening" "Afternoon" "Evening" "Night" "Afternoon" "Evening" "Evening"
#[151] "Morning" "Noon" "Noon" "Evening" "Evening" "Night" "Morning" "Noon" "Noon" "Evening" "Evening"
timing_cat <- c("Dawn", "Morning", "Noon", "Afternoon", "Evening", "Night" )
factor_time <- factor(char_time, ordered = T, levels = timing_cat)
summary(factor_time)
#Dawn Morning Noon Afternoon Evening Night
#6 7 39 43 44 22
#Most of the incidents happen between noon and 8pm, so no, there are not more incidents happening at the end of the day
# cleaning up the NAs
summary(X919_data[is.na(X919_data$'Call initiated to: Police (911)')])
ambulance <- X919_data$`Call initiated to: Ambulance (911)`
overdosed <- X919_data$Overdose
amb_df <- as.data.frame(ambulance)
amb_df[is.na(amb_df)] <- 0 # replacing na with 0
over_df <- as.data.frame(overdosed)
over_df[is.na(over_df)] <- 0