在没有funs()的情况下,使用其他列作为参数在summary_at()和summary_all()中起作用 [英] Use of other columns as arguments to function in summarize_at() and summarize_all() without funs()
本文介绍了在没有funs()的情况下,使用其他列作为参数在summary_at()和summary_all()中起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I'm looking for an alternative to this (which was provided as a solution here) that does not use funs()
since funs()
is soft deprecated as of dplyr 0.8.0:
mtcars %>% group_by(cyl) %>%
summarize_at(vars(disp, hp), funs(weighted.mean(.,wt)))
# cyl disp hp
# <dbl> <dbl> <dbl>
#1 4.00 110 83.4
#2 6.00 185 122
#3 8.00 362 209
推荐答案
正如R警告所说,您必须使用(在这种情况下)lambda列表
As the R warning says, you have to use (in this case) a list of lambdas
mtcars %>% group_by(cyl) %>%
summarize_at(vars(disp, hp), list(~weighted.mean(., wt)))
这篇关于在没有funs()的情况下,使用其他列作为参数在summary_at()和summary_all()中起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文