Last active
March 28, 2020 03:10
-
-
Save AABoyles/df7e8be3ec88345c47a6fac95f93856b to your computer and use it in GitHub Desktop.
Compute the Monthly Death Tolls from the JHU CSSE COVID-19 Time-Series Data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
month | Deaths | newDeaths | |
---|---|---|---|
1 | 213 | 213 | |
2 | 2941 | 2728 | |
3 | 12973 | 10032 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(lubridate) | |
raw <- read_csv('https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Deaths.csv') | |
processed <- raw %>% | |
mutate(Location = ifelse(is.na(`Province/State`), `Country/Region`, paste(`Province/State`, `Country/Region`, sep = ', '))) %>% | |
select(Location, `1/22/20`:`3/21/20`) %>% | |
pivot_longer(cols = `1/22/20`:`3/21/20`, names_to = 'Date', values_to = "Deaths") %>% | |
mutate(Date = mdy(Date)) %>% | |
group_by(Date) %>% | |
summarise(Deaths = sum(Deaths)) %>% | |
mutate(month = month(Date)) %>% | |
group_by(month) %>% | |
summarise(Deaths = max(Deaths)) %>% | |
mutate(newDeaths = Deaths - lag(Deaths)) | |
processed$newDeaths[1] <- processed$Deaths[1] | |
write_csv(processed, "COVID19MonthlyDeathToll.csv") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(lubridate) | |
theDates <- mdy('03-21-2020'):mdy('01-22-2020') %>% | |
as.Date(origin=ymd('1970-01-01')) %>% | |
as.character(format="%m-%d-%Y") | |
for(theDate in theDates){ | |
temp <- read_csv(paste0('https://github.com/CSSEGISandData/COVID-19/raw/master/csse_covid_19_data/csse_covid_19_daily_reports/', theDate, '.csv')) | |
write_csv(temp, paste0(theDate,'.csv')) | |
} | |
for(theDate in theDates){ | |
temp <- read_csv(paste0(theDate, '.csv')) %>% | |
select(`Province/State`, Deaths) %>% | |
mutate(date = theDate) | |
if(theDate == theDates[1]){ | |
raw <- temp | |
} else { | |
raw <- raw %>% | |
bind_rows(temp) | |
} | |
} | |
theDates <- mdy('03-27-2020'):mdy('03-22-2020') %>% | |
as.Date(origin=ymd('1970-01-01')) %>% | |
as.character(format="%m-%d-%Y") | |
for(theDate in theDates){ | |
temp <- read_csv(paste0(theDate, '.csv')) %>% | |
select(`Province/State` = `Province_State`, Deaths) %>% | |
mutate(date = theDate) | |
raw <- raw %>% | |
bind_rows(temp) | |
} | |
processed <- raw %>% | |
filter(`Province/State` == "New York") %>% | |
#filter(`Country/Region` == 'US') %>% | |
select(date, Deaths) %>% | |
group_by(date) %>% | |
summarize(deaths = sum(Deaths)) %>% | |
View |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment