Function writing passing column reference to group_by

前端 未结 1 1488
感动是毒
感动是毒 2021-01-22 19:59

I\'m very new to R. Trying to define a function that groups a data set (group_by) and then creates summary statistics based on the groupings (dplyr, summarise_each).

Wi

1条回答
  •  梦毁少年i
    2021-01-22 20:13

    This is the usual way you'd do this:

    foo <- function(data,column){
      data %>%
        group_by_(.dots = column) %>%
        summarise_each(funs(mean))
    }
    
    foo(mtcars,"cyl")
    foo(mtcars,"gear")
    

    0 讨论(0)
提交回复
热议问题