I uploaded the dataset. but how do I show those who died in Europe.
df <- read.csv ('https://raw.githubusercontent.com/ulklc/covid19-timeseries/master/countryReport/raw/rawReport.csv')
europe <-- df[df$region =="Europe"]
df$death [europe]
I uploaded the dataset. but how do I show those who died in Europe.
df <- read.csv ('https://raw.githubusercontent.com/ulklc/covid19-timeseries/master/countryReport/raw/rawReport.csv')
europe <-- df[df$region =="Europe"]
df$death [europe]
We can filter only the European countries and calculate number of deaths by country.
This can be done in base R :
df1 <- aggregate(death~countryName, subset(df, region =="Europe"), sum)
dplyr
library(dplyr)
df1 <- df %>%
filter(region == 'Europe') %>%
group_by(countryName) %>%
summarise(total_death = sum(death))
and in data.table
df1 <- setDT(df)[region == 'Europe', (total_death = sum(death)), countryName]
We can also use the subset
in aggregate
aggregate(death~countryName, df, subset = region =="Europe"), sum)
Or using rowsum
with(subset(df, region == 'Europe'), rowsum(death, countryName))