Commit 615c1bf2 authored by Facundo Muñoz's avatar Facundo Muñoz ®️
Browse files

Add comments and clean up calculation of Dfr3.

parent f941a4de
...@@ -147,8 +147,8 @@ Lock$name <- reorder(Lock$name, Lock$T80) ...@@ -147,8 +147,8 @@ Lock$name <- reorder(Lock$name, Lock$T80)
```{r country-data} ```{r country-data}
## Variables relative to European countries: ## Variables relative to African countries:
## group, name, lockdown date, population, cumulated deaths, ## group, name, lockdown date, population, cumulated deaths (as of today),
## and death rate. ## and death rate.
country_data <- country_data <-
map_dfr( map_dfr(
...@@ -189,6 +189,7 @@ country_data <- ...@@ -189,6 +189,7 @@ country_data <-
## with population and lockdown date added ## with population and lockdown date added
Dfr <- deaths_by_ctry_dt %>% Dfr <- deaths_by_ctry_dt %>%
inner_join( inner_join(
## filter African countries by joining
country_data, country_data,
by = "name" by = "name"
) %>% ) %>%
...@@ -196,8 +197,9 @@ Dfr <- deaths_by_ctry_dt %>% ...@@ -196,8 +197,9 @@ Dfr <- deaths_by_ctry_dt %>%
# Order name levels in decreasing order of death rate # Order name levels in decreasing order of death rate
name = fct_reorder(name, death_rate, .desc = TRUE) name = fct_reorder(name, death_rate, .desc = TRUE)
) %>% ) %>%
select(name, date, deaths, pop, lockdown) select(name, date, deaths, pop, lockdown, current_cum_deaths = cum_deaths)
## onam is equal to african_countries but ordered by decreasing death-rate
onam <- levels(Dfr$name) onam <- levels(Dfr$name)
## Names of countries with less than 25 cumulated deaths ## Names of countries with less than 25 cumulated deaths
...@@ -207,22 +209,20 @@ nam25 <- country_data %>% ...@@ -207,22 +209,20 @@ nam25 <- country_data %>%
onam2 <- onam[!(onam %in% nam25)] onam2 <- onam[!(onam %in% nam25)]
## the condition on deaths >= 0 is needed because Spain has declared a
## negative count in early June
Dfr2 <- subset(Dfr, name %in% onam2 & deaths >= 0)
Dfr2$name <- factor(as.character(Dfr2$name),
levels = onam2)
Dfr3 <- do.call( ## Compute day since first reported death by country, for countries with at
"rbind", ## least 25 cumulative deaths
by(Dfr2, Dfr3 <- Dfr %>%
list(name = Dfr2$name), ## the condition on deaths >= 0 is needed because Spain has declared a
function(x){ ## negative count in early June
x$day = as.numeric(x$date - min(x$date, na.rm = T)) filter(current_cum_deaths >= 25, deaths >= 0) %>%
x droplevels() %>%
})) group_by(name) %>%
Dfr3$name <- factor(as.character(Dfr3$name), mutate(
levels = onam2) day = as.integer(date - min(date, na.rm = TRUE))
) %>%
ungroup() %>%
select(-current_cum_deaths)
## use function "by" to loop over the country names ## use function "by" to loop over the country names
L2 <- by(Dfr3, L2 <- by(Dfr3,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment