This question is related to the a similar post. Function writing passing column reference to group_by
However, I want to pass several inputs to a function that uses group_by_() and summarise_().
Here's my function:
foo <- function(data,column,x1,x2){
data %>%
group_by_(.dots = column) %>%
summarise_(.dots= c(~mean(x1), ~mean(x2)))
}
However, when I run
foo(mtcars,"cyl", "disp", "hp")
I get the following error.
Error in UseMethod("as.lazy_dots") :
no applicable method for 'as.lazy_dots' applied to an object of class "c('double', 'numeric')"
In addition: Warning message:
In mean.default(x1) : argument is not numeric or logical: returning NA
Can anyone tell me where I'm doing wrong?