knitr::opts_chunk$set(
  collapse = TRUE,
  message=FALSE, 
  warning=FALSE,
  comment = "#>"
)

The covid19swiss R package provides a tidy format dataset of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) pandemic outbreak in Switzerland cantons and Principality of Liechtenstein (FL).

Data structure

The covid19swiss dataset includes the following fields:

Where the available data_type field includes the following cases:

The data organized in a long format:

library(covid19swiss)

head(covid19swiss)

It is straightforward to transform the data into a wide format with the pivot_wider function from the tidyr package:

library(tidyr)

covid19swiss_wide <- covid19swiss %>% 
  pivot_wider(names_from = data_type, values_from = value)

head(covid19swiss_wide)

Query and summarise the data

The following examples demonstrate simple methods for query and summarise the data with the dplyr and tidyr packages.

Cases summary by canton

The first example demonstrates how to query the total confirmed, recovered, and death cases by canton as of April 8th:

library(dplyr)

covid19swiss %>%
  filter(date == as.Date("2020-04-10"),
         data_type %in% c("total_confirmed", "total_recovered", "total_death")) %>%
  select(location, value, data_type) %>%
  pivot_wider(names_from = data_type, values_from = value) %>%
  arrange(-total_confirmed)

Note: some fields, such as total_recovered or total_tested, are not available for some cantons and marked as missing values (i.e., NA)

Calculating rates for Canton of Geneva

In the next example, we will filter the dataset for the Canton of Geneva and calculate the following metrics:

covid19swiss %>% dplyr::filter(location == "GE",
                               date == as.Date("2020-04-10")) %>%
  dplyr::select(data_type, value) %>%
  tidyr::pivot_wider(names_from = data_type, values_from = value) %>%
  dplyr::mutate(positive_tested = round(100 * total_confirmed / total_tested, 2),
                death_rate = round(100 * total_death / total_confirmed, 2),
                recovery_rate = round(100 * total_recovered / total_confirmed, 2)) %>%
  dplyr::select(positive_tested, recovery_rate, death_rate) 

Values are in precentage

Separating between Switzerland and Principality of Liechtenstein

The raw data include both Switzerland and the Principality of Liechtenstein. Separating the data by country can be done by using the location field:

switzerland <- covid19swiss %>% filter(location != "FL")

head(switzerland)

liechtenstein <- covid19swiss %>% filter(location == "FL")

head(liechtenstein)


RamiKrispin/covid19swiss documentation built on May 18, 2020, 11:54 a.m.