Kevin
Kevin

Reputation: 533

Use of other columns as arguments to function in summarize_at() and summarize_all() without funs()

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  

Upvotes: 0

Views: 114

Answers (1)

Ric S
Ric S

Reputation: 9247

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)))

Upvotes: 1

Related Questions