-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsummary.R
More file actions
96 lines (72 loc) · 2.33 KB
/
summary.R
File metadata and controls
96 lines (72 loc) · 2.33 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
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
library(dplyr)
library(tidyverse)
geographics <- read.csv("https://raw.githubusercontent.com/info201b-au2022/INFO201-Group25/main/data/geographics.csv")
View(geographics)
# Number of Observations
num_observations <- nrow(geographics)
print(num_observations)
# Total Deaths from 2013 - 2018
total_deaths <- sum(geographics$n_killed)
print(total_deaths)
# State with total max death
state_deaths <- geographics %>%
group_by(state) %>%
summarise(total_state_deaths = sum(n_killed))
max_state_deaths <- state_deaths %>%
filter(total_state_deaths == max(total_state_deaths)) %>%
pull(state)
print(max_state_deaths)
# State with Least Death
min_state_deaths <- state_deaths %>%
filter(total_state_deaths == min(total_state_deaths)) %>%
pull(state)
print(min_state_deaths)
# City with Max Death
geo_with_location <-
unite(geographics, "location", city_or_county:state, sep = ", " , na.rm = TRUE, remove = FALSE)
View(geo_with_location)
location_deaths <- geo_with_location %>%
group_by(location) %>%
summarise(total_city_deaths = sum(n_killed))
View(location_deaths)
max_city_deaths <- location_deaths %>%
filter(total_city_deaths == max(total_city_deaths)) %>%
pull(location)
print(max_city_deaths)
# Cities with Least Death (0s)
min_city_deaths <- location_deaths %>%
filter(total_city_deaths == min(total_city_deaths))
min <- nrow(min_city_deaths)
print(min)
#select year from date
year_col <- geographics %>%
mutate(year = format(as.Date(date, format="%m/%d/%Y"),"%Y"))
View(year_col)
# Year with most Death
year_deaths <- year_col %>%
group_by(year) %>%
summarise(total_year_deaths = sum(n_killed))
View(year_deaths)
max_year_deaths <- year_deaths %>%
filter(total_year_deaths == max(total_year_deaths)) %>%
pull(year)
print(max_year_deaths)
# Year with least Death
min_year_deaths <- year_deaths %>%
filter(total_year_deaths == min(total_year_deaths)) %>%
pull(year)
print(min_year_deaths)
# Date with most Death
date_deaths <- geographics %>%
group_by(date) %>%
summarise(total_date_deaths = sum(n_killed))
View(date_deaths)
max_date_deaths <- date_deaths %>%
filter(total_date_deaths == max(total_date_deaths)) %>%
pull(date)
print(max_date_deaths)
# Date with least Death
min_date_deaths <- date_deaths %>%
filter(total_date_deaths == min(total_date_deaths))
min_date <- nrow(min_date_deaths)
print(min_date)