Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(tidyverse)
- # x is a grouped tibble, my_col is the column to peel
- my_function <- function(x, my_col){
- my_col_enc <- enquo(my_col)
- # Trying to grab the groups and then peel off the column
- x_grp <- x %>% group_vars()
- excluded <- x_grp[!is.element(x_grp, as.character(my_col_enc))]
- # My calculations are two-tiered as described in the original description
- # simplifying for example
- x %>% group_by(excluded) %>% tally()
- }
- # This should be equivalent to mtcars %>% group_by(gear) %>% tally()
- mtcars %>% group_by(cyl, gear) %>% my_function(cyl)
- library(tidyverse)
- my_function <- function(x, my_col){
- my_col_enc <- enquo(my_col)
- # Trying to grab the groups and then peel off the column
- x_grp <- x %>% group_vars()
- # here, make sure this is a symbol, else it'll group as character later (e.g. 'gear')
- excluded <- rlang::sym(x_grp[!is.element(x_grp, as.character(my_col_enc))])
- # need to use !'s to deal with the symbol
- x %>% group_by(!!excluded) %>% tally()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement