首页 > 解决方案 > 数据集使用和变量选择

问题描述

我上传了数据集。但是我如何展示那些在欧洲死去的人。

df <- read.csv ('https://raw.githubusercontent.com/ulklc/covid19-timeseries/master/countryReport/raw/rawReport.csv')

europe <-- df[df$region =="Europe"]

df$death [europe]

标签: r

解决方案


我们只能过滤欧洲国家并按国家计算死亡人数。

这可以在基础 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))

并且在data.table

df1 <- setDT(df)[region == 'Europe', (total_death = sum(death)), countryName]

推荐阅读