dplyr - groupby on multiple columns using variable names

前端 未结 4 962
长发绾君心
长发绾君心 2020-12-08 07:33

I am working with R Shiny for some exploratory data analysis. I have two checkbox inputs that contain only the user-selected options. The first checkbox input contains only

4条回答
  •  無奈伤痛
    2020-12-08 07:52

    With dplyr 1.0.0, we have the following possibility based on the "normal" group_by:

    library(dplyr)
    
    group_cols <- c("vs", "am")
    
    mtcars %>% 
      group_by(across(all_of(group_cols))) %>% 
      summarize(mean_wt = mean(wt))
    

提交回复
热议问题