rm(list = ls())
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)
library(stringr)

Data preparation

ebola_df <- read.csv("https://github.com/rjmirza/Data-607/raw/master/Ebola_data.csv")

summary(ebola_df)
##                      Country            Date     
##  Liberia                 :365   2016-03-23:  12  
##  Guinea                  :259   2015-07-03:  11  
##  Sierra Leone            :259   2015-07-06:  11  
##  Nigeria                 :255   2015-07-07:  11  
##  Senegal                 :254   2015-07-08:  11  
##  United States of America:245   2015-07-09:  11  
##  (Other)                 :848   (Other)   :2418  
##  Cumulative.no..of.confirmed..probable.and.suspected.cases
##  Min.   :    0                                            
##  1st Qu.:    1                                            
##  Median :    8                                            
##  Mean   : 2554                                            
##  3rd Qu.: 3657                                            
##  Max.   :14122                                            
##  NA's   :8                                                
##  Cumulative.no..of.confirmed..probable.and.suspected.deaths
##  Min.   :   0                                              
##  1st Qu.:   0                                              
##  Median :   6                                              
##  Mean   :1028                                              
##  3rd Qu.:2386                                              
##  Max.   :4806                                              
## 
head(ebola_df)

Totals cases for each country

total_cases <- ebola_df %>% select(Country:Cumulative.no..of.confirmed..probable.and.suspected.cases)

head(total_cases, 100)
cases_by_country <- total_cases %>% group_by("Country" = Country) %>% summarise("Total cases" = sum(Cumulative.no..of.confirmed..probable.and.suspected.cases), "Average cases" = round(mean(Cumulative.no..of.confirmed..probable.and.suspected.cases),0))

head(cases_by_country)

Totals deaths for each country

total_deaths <- ebola_df %>% select(Country, Date, Cumulative.no..of.confirmed..probable.and.suspected.deaths)

total_deaths
deaths_by_country <- total_deaths %>% group_by("Country" = Country) %>% summarise("Total deaths" = sum(Cumulative.no..of.confirmed..probable.and.suspected.deaths), "Average deaths" = round(mean(Cumulative.no..of.confirmed..probable.and.suspected.deaths),0))

deaths_by_country

Joining two data sets and finding the percentage of deaths

joined_ebola_data <- inner_join(cases_by_country, deaths_by_country, by = "Country")

joined_ebola_data <- joined_ebola_data %>% select(Country, `Total cases`, `Total deaths`) %>%  mutate("Percentage of deaths" =  round((`Total deaths`/`Total cases`)*100, 2))

joined_ebola_data$Country <- as.character(joined_ebola_data$Country)
joined_ebola_data$`Total cases` <- as.numeric(joined_ebola_data$`Total cases`)
joined_ebola_data$`Total deaths` <- as.numeric(joined_ebola_data$`Total deaths`)
joined_ebola_data$`Percentage of deaths` <- as.numeric(joined_ebola_data$`Percentage of deaths`)

joined_ebola_data