-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcode.R
More file actions
61 lines (45 loc) · 2.3 KB
/
code.R
File metadata and controls
61 lines (45 loc) · 2.3 KB
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
setwd("D:/Fellowship Manchester/Hackathon/Data")
library(dplyr)
crime <- read.csv("D:/Fellowship Manchester/Hackathon/Data/us_crime_2018.csv")
table(crime$offense_group)
crime <- crime %>%
filter(city_name == "Los Angeles")
#crime <- crime %>%
# filter(offense_group == "arson" | offense_group == "assault offenses" |
# offense_group == "destruction/damage/vandalism of property (except arson)" |
# offense_group == "disorderly conduct" | offense_group == "driving under the influence" |
# offense_group == "drug/narcotic offenses" | offense_group == "larceny/theft offenses" |
# offense_group == "motor vehicle theft" | offense_group == "trespass of real property" |
# offense_group == "family offenses, nonviolent")
crime <- crime %>%
mutate(date = substr(date_single, 0, 10),
date = lubridate::ymd(date))
games <- read.csv("D:/Fellowship Manchester/Hackathon/Data/retrosheet_gl_2018.csv")
games <- games %>%
filter(city == "Los Angeles")
games <- games %>%
filter(name == "Dodger Stadium") %>%
mutate(date = lubridate::ymd(date))
results <- read.csv("D:/Fellowship Manchester/Hackathon/Data/Dodgers_games.csv")
results <- results %>%
rename(Date = 2) %>%
mutate(date = lubridate::mdy(`Date`))
results <- results %>%
filter(stringr::str_detect(Opponent, "vs "))
days <- crime %>%
group_by(date) %>%
summarise(crimes = n(),
arson = length(uid[offense_group == "arson"]),
assault = length(uid[offense_group == "assault offenses"]),
damage = length(uid[offense_group == "destruction/damage/vandalism of property (except arson)"]),
disorder = length(uid[offense_group == "disorderly conduct"]),
dui = length(uid[offense_group == "driving under the influence"]),
drug = length(uid[offense_group == "drug/narcotic offenses"]),
larceny = length(uid[offense_group == "larceny/theft offenses"]),
vehi_theft = length(uid[offense_group == "motor vehicle theft"]),
vehi_theft = length(uid[offense_group == "trespass of real property"]),
family = length(uid[offense_group == "family offenses, nonviolent"]))
days <- days %>%
left_join(games, by = "date") %>%
left_join(results, by = "date")
write.csv(days, "days.csv")