📜  如何在函数中使用 group_by? - R 编程语言代码示例

📅  最后修改于: 2022-03-11 14:52:00.038000             🧑  作者: Mango

代码示例1
mytable <- function( x, group ) {
  x %>% 
    group_by( .data[[group]] ) %>% 
    summarise( n = n() )
}

group_string <- 'Species'

mytable( iris, group_string )

`summarise()` ungrouping output (override with `.groups` argument)
# A tibble: 3 x 2
  Species        n
        
1 setosa        50
2 versicolor    50
3 virginica     50