Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
UMR-ASTRE
Covid19-Mortality-Visualisation
Commits
615c1bf2
Commit
615c1bf2
authored
Aug 20, 2020
by
Facundo Muñoz
®️
Browse files
Add comments and clean up calculation of Dfr3.
parent
f941a4de
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/Covid19MortalityWCAfrica.Rmd
View file @
615c1bf2
...
...
@@ -147,8 +147,8 @@ Lock$name <- reorder(Lock$name, Lock$T80)
```{r country-data}
## Variables relative to
Europe
an countries:
## group, name, lockdown date, population, cumulated deaths,
## Variables relative to
Afric
an countries:
## group, name, lockdown date, population, cumulated deaths
(as of today)
,
## and death rate.
country_data <-
map_dfr(
...
...
@@ -189,6 +189,7 @@ country_data <-
## with population and lockdown date added
Dfr <- deaths_by_ctry_dt %>%
inner_join(
## filter African countries by joining
country_data,
by = "name"
) %>%
...
...
@@ -196,8 +197,9 @@ Dfr <- deaths_by_ctry_dt %>%
# Order name levels in decreasing order of death rate
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)
## Names of countries with less than 25 cumulated deaths
...
...
@@ -207,22 +209,20 @@ nam25 <- country_data %>%
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(
"rbind",
by(Dfr2,
list(name = Dfr2$name),
function(x){
x$day = as.numeric(x$date - min(x$date, na.rm = T))
x
}))
Dfr3$name <- factor(as.character(Dfr3$name),
levels = onam2)
## Compute day since first reported death by country, for countries with at
## least 25 cumulative deaths
Dfr3 <- Dfr %>%
## the condition on deaths >= 0 is needed because Spain has declared a
## negative count in early June
filter(current_cum_deaths >= 25, deaths >= 0) %>%
droplevels() %>%
group_by(name) %>%
mutate(
day = as.integer(date - min(date, na.rm = TRUE))
) %>%
ungroup() %>%
select(-current_cum_deaths)
## use function "by" to loop over the country names
L2 <- by(Dfr3,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment