7  Lösungen Plague

7.1 Lösung 1

#Aufgabe 1 

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Deaths <- read.csv("https://raw.githubusercontent.com/SurgicalInformatics/healthyr_book/master/data/global_burden_disease_cause-year-sex-income.csv")

summary_data1 <- 
  Deaths%>% 
  group_by(year) %>% 
  summarise(total_per_year = sum(deaths_millions))

7.2 Lösung 2.1

# Aufgabe 2.1

summary_data2 <- 
  Deaths %>% 
  group_by(sex, year) %>% 
  summarise(sum(deaths_millions))
`summarise()` has grouped output by 'sex'. You can override using the `.groups`
argument.

7.3 Lösung 2.2

# Aufgabe 2.2
Deaths %>% 
  select(deaths_millions, income, sex) %>% 
  filter(sex == "Male") %>% 
  filter(income == "High")%>% 
  summarise(Tode = sum(deaths_millions))
Deaths %>% 
  select(deaths_millions, income, sex) %>% 
  filter(sex == "Female")%>% 
  filter(income == "Low") %>% 
  summarise(Tode = sum(deaths_millions))

7.4 Lösung 2.3

# Aufgabe 2.3

Deaths %>%
  group_by(cause) %>% 
  filter(year >= 2005,
         sex == "Male",
         income == "Low") %>% 
  summarise(Total = sum(deaths_millions), 
            durchschnittliche = mean(deaths_millions))

7.5 Lösung 3.1

# Aufgabe 3.1 

summary_data3 <- 
  Deaths %>% 
  group_by(year, cause) %>% 
  summarise(total_per_cause = sum(deaths_millions))
`summarise()` has grouped output by 'year'. You can override using the
`.groups` argument.

7.6 Lösung 3.2

# Aufgabe 3.2

Deaths %>%
  group_by(income) %>% 
  summarise(Total = sum(deaths_millions))
Deaths %>% 
  summarise(sum(deaths_millions))

7.7 Lösung 4

# Aufgabe 4

summary_data4 <- Deaths %>%
  summarise(Gesamt = sum(deaths_millions))


summary_data5 <- Deaths %>%
  group_by(cause)%>%
  summarise(total_per_cause = sum(deaths_millions)) %>% 
  mutate(InProzent = total_per_cause/359.85)