【发布时间】:2016-01-22 07:41:58
【问题描述】:
这个问题与一个类似的帖子有关。 Function writing passing column reference to group_by
但是,我想将几个输入传递给使用 group_by_() 和 summarise_() 的函数。
这是我的功能:
foo <- function(data,column,x1,x2){
data %>%
group_by_(.dots = column) %>%
summarise_(.dots= c(~mean(x1), ~mean(x2)))
}
但是,当我跑步时
foo(mtcars,"cyl", "disp", "hp")
我收到以下错误。
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
谁能告诉我哪里做错了?
【问题讨论】:
-
我注意到您没有接受对您提出的任何问题的任何回答。尽管接受答案不是强制性的,但如果其中一个答案对您有用,那么这样做被认为是一种好的做法。这将为未来的读者提供有关解决方案价值的线索。另请参阅此帮助页面:What should I do when someone answers my question?
标签: r function group-by parameter-passing dplyr