-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_in_data.R
117 lines (101 loc) · 4.67 KB
/
read_in_data.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
# Import data
library(tidyverse)
cyclists <- read_csv("data/cyclists", col_names = TRUE,
col_types = cols(
col_double(), # incident ID
col_double(), # cyclist ID
col_factor(), # sex
col_double(), # age
col_character(), # age range
col_factor(), # status
col_character(), # location
col_character() # notes
))
cyclists$sex <- factor(cyclists$sex, levels=c('M', 'F', ''))
pedestrians <- read_csv("data/pedestrians", col_names = TRUE,
col_types = cols(
col_double(), # incident ID
col_double(), # pedestrian ID
col_factor(), # sex
col_double(), # age
col_character(), # age range
col_factor(), # status
col_character(), # location
col_character() # notes
))
pedestrians$sex <- factor(pedestrians$sex, levels=c('M', 'F', ''))
others <- read_csv("data/other", col_names = TRUE,
col_types = cols(
col_double(), # incident ID
col_double(), # other ID
col_factor(), # sex
col_double(), # age
col_character(), # age range
col_factor(), # status
col_character(), # location
col_character() # notes
))
others$sex <- factor(others$sex, levels=c('M', 'F', ''))
incidents <- read_csv("data/incidents", col_names = TRUE,
col_types = cols(
col_double(), # incident ID
col_date(), # date
col_character(), # time
col_character(), # approx time
col_character(), # country
col_character(), # province
col_character(), # region
col_character(), # location
col_double(), # revision/project ID
col_character(), # entry date-time
col_character() # notes
))
# Drop notes
incidents_unfiltered <- incidents
incidents <- incidents[,-c(which(colnames(incidents)=="notes"))]
# Add DOW
incidents$dow <- lubridate::wday(incidents$date, label = T)
incidents <- incidents[,c(1,2,11,3,4,5,6,7,8,9,10)]
#temp <- incidents$time
#temp2 <- lubridate::parse_date_time(temp, orders = c("%H:%M %p"))
#incidents$time <- lubridate::parse_date_time(incidents$time,orders=c("%I:%M %p"))
vehicles <- read_csv("data/vehicles", col_names = TRUE,
col_types = cols(
col_double(), # incident ID
col_double(), # vehicle ID
col_factor(), # type
col_character(), # make
col_character(), # model
col_character(), # year
col_character(), # work flag
col_character() # notes
))
in_vehicles <- read_csv("data/in_vehicles", col_names = TRUE,
col_types = cols(
col_double(), # incident ID
col_double(), # vehicle ID
col_double(), # in_vehicle ID
col_double(), # driver flag
col_factor(), # sex
col_double(), # age
col_character(), # age rage
col_factor(), # injury status
col_character(), # location
col_character() #notes
))
in_vehicles$sex <- factor(in_vehicles$sex, levels=c('M', 'F', ''))
structures <- read_csv("data/structures", col_names = TRUE,
col_types = cols(
col_double(), # incident ID
col_double(), # structure ID
col_factor(), # structure type
col_factor(), # structure status
col_character() # notes
))
sources <- read_csv("data/sources", col_names = TRUE,
col_types = cols(
col_double(), # incident ID
col_character(), # url
col_character(), # archive url
col_character() # notes
))