Example:
library(dplyr)
df <- tibble(a = c(10, 10, 10, 20, 20),
b = c(1, 2, 10, 2, 4))
## produces desired result:
df %>%
group_by(a) %>%
summarize(mn = mean(b), md = median(b))
stats <- function(x){
list(mn = mean(x), md = median(x)) }
## object 'b' not found:
df %>%
group_by(a) %>%
summarize(!!! stats(b))
The call stats(b)
does not see column b
. What is the simplest solution that does not involve changing the stats
function?
R version 3.4.3, dplyr version 0.7.2