我知道这是一个经典问题,档案中也有类似的问题,但我觉得答案并不真正适用于这个案例。基本上,我想获取一个数据框(每个地区在柏林的 covid 病例),计算列的总和并创建一个新的数据框,其中一列代表地区名称,另一列代表总数。所以我写了
covid_bln <- read.csv('https://www.berlin.de/lageso/gesundheit/infektionsepidemiologie-infektionsschutz/corona/tabelle-bezirke-gesamtuebersicht/index.php/index/all.csv?q=', sep=';')
c_tot<-data.frame('district'=c(), 'number'=c())
for (n in colnames(covid_bln[3:14])){
x<-data.frame('district'=c(n), 'number'=c(sum(covid_bln$n)))
c_tot<-rbind(c_tot, x)
next
}
print(c_tot)
哪个名称可以正常工作,但仅返回第 8 区的病例数,但返回所有区。如果您有任何建议,甚至涉及到其他功能的使用,那就太好了。谢谢