gpt4 book ai didi

r - summarise_each 已弃用 - 新 summarise_at 引发错误

转载 作者:行者123 更新时间:2023-12-04 02:03:17 33 4
gpt4 key购买 nike

我正在使用以下代码和数据来汇总值:

  bvsubcount.subset %>% 
group_by(bv.parentbvid) %>%
summarise_each(funs(sum), c(`2003`:`2005`)) -> bvsubcount.subset

日期示例:
bvsubcount.subset <- setNames(data.frame(c("AT", "DE", "IT"), c("ID1", "ID1", "ID2"),1:3,5:7,3:5), 
c("bv.sub.country.iso", "bv.parentbvid", 2003:2005))

到目前为止,这工作正常,但最近我收到以下警告:
`summarise_each()` is deprecated.
Use `summarise_all()`, `summarise_at()` or `summarise_if()` instead.
To map `funs` over a selection of variables, use `summarise_at()`

如果我使用 summarise_at ,但是,使用以下代码,我收到错误错误:
bvsubcount.subset %>% 
group_by(bv.parentbvid) %>%
summarise_at(funs(sum), c(`2003`:`2005`)) -> bvsubcount.subset


.vars` must be a character/numeric vector or a `vars()` object, not list

如何使用新的汇总函数来避免警告并仍然使用类似的代码结构?

最佳答案

error正在暗示 .vars必须是变量名称的字符向量,因此您可以尝试以下操作:

bvsubcount.subset %>% 
+ group_by(bv.parentbvid) %>%
+ summarise_at(.vars = c("2003","2004","2005"),.funs = sum) ->
bvsubcount.subset

如果您不想明确提及每个数字列名称,请替换 c("2003","2004","2005")as.character(2003:2005)

关于r - summarise_each 已弃用 - 新 summarise_at 引发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45794946/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com