library(tidyverse)6.1.i - Class Activity
This assignment is intended to get you familiar with the tidyverse using real COVID-19 data.
The following code chunk scrapes the .csv files we will be analyzing from the web renames and selects the subset of columns that we will be using for analysis.
url <- "https://srhdpeuwpubsa.blob.core.windows.net/whdh/COVID/"
url_case <- paste0(url, "WHO-COVID-19-global-table-data.csv")
covid_case <- read_csv(url_case) |>
select(name = Name, region = `WHO Region`,
case_total = `Cases - cumulative total`,
case_pop = `Cases - cumulative total per 100000 population`,
death_total = `Deaths - cumulative total`,
death_pop = `Deaths - cumulative total per 100000 population`)The renamed columns that remain are:
name: Country nameregion: World Health Organization (WHO) region.case_total: Cumulative number of reported COVID cases since Jan 2020case_pop: Cumulative number of reported COVID cases per 100,000 people since Jan 2020death_total: Cumulative number of reported COVID deaths since Jan 2020death_pop: Cumulative number of reported COVID deaths per 100,000 people since Jan 2020
1 Problem
We want to know how the different regions of the world fared in terms of their covid case rates per 100,000 people. To get started with this, create a new dataframe called covid_case_region that contains the country-level averages (i.e., mean()) for both cases and deaths per 100,000 people by region. Call the variable containing the averages mean_case_pop. Be sure to remove missing values prior to calculating the averages. Question for Canvas: What is the mean deaths per 100,000 people in the “Africa” region, rounded to the nearest whole number?
## covid_case_region <- covid_case |>
## group_by(#...#) |>
## summarize(#...#)
## covid_case_region2 Problem
Notice that we have two issues with our summary. The “other” region has no non-missing observations (indicated by the NaN values) and there is an NA region that contains an unknown number of countries. Please update the covid_case_region dataframe to exclude any rows that contain NaN values for mean_case_pop, as well as any rows with missing region information. Hint: check out the is.nan() and is.na() function for help in excluding a row that contain NaN or NA values in a particular column. Your updated dataset should have precisely 6 rows.
## covid_case_region <- covid_case_region |>
## #...#
## covid_case_region3 Problem
Arrange the covid_case_region dataframe so that the average deaths per 100,000 people go from smallest to largest. Question for Canvas: which region has the second largest deaths per 100,000 people due to COVID?
## covid_case_region |>
## #...#4 Problem
Discuss with a partner: The deaths per 100,000 people in the Europe region appears to be nearly 10 times larger than the deaths per 100,000 people in the Africa region. Does this imply that COVID was 10 times more deadly for Europeans? Explain why or why not, knowing that this course will not provide a definitive answer.
Replace this text with your answer. Optional if discussing with a partner but required if doing the assignment on your own.
5 Problem
Write a new and single R statement (using pipes |>) that starts from the original covid_case dataframe and does the following:
- Calculates the average of
case_popanddeath_popby region (as previously done) - Omits the
NaNrows andNArows (as previously done) - Calculates the deaths per reported case (i.e.,
death_rate) using \(100*\frac{\text{mean\_death\_pop}}{\text{mean\_case\_pop}}\) usingmutate - Retains only rows with
death_rateexceeding 0.8.
Question for Canvas: How many regions have death rates exceeding 0.8?
## covid_case |>
## group_by(#...#) |>
## summarize(#...#) |>
## filter(#...#) |>
## mutate(#...#) |>
## filter(#...#)