Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR R

Pass argument to group_by

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
  <fct>      <int>
1 setosa        50
2 versicolor    50
3 virginica     50
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Pass #argument
ADD COMMENT
Topic
Name
9+5 =