这里怎么了?这样做是可行的:
iris %>%
filter(Species == "setosa") %>%
summarise(msl = mean(Sepal.Length), msw = mean(Petal.Width))并产生:
msl msw
1 5.006 0.246但是这个函数不起作用:
means <- function(data, value){
data <- enquo(data)
value <- enquo(value)
data %>%
filter(Species == !!value) %>%
summarise(msl = mean(Sepal.Length), msw = mean(Petal.Width))
}means(iris, "setosa")会产生以下错误:
UseMethod中的错误(“filter_”):不适用于类"c('quosure','filter_‘)中调用的类filter_(.data,.dots =compat_as_lazy_dots(.))中的对象
发布于 2018-11-17 13:22:40
错误消息非常简单,您不能过滤质量。我不知道你为什么要保留你的数据,但这会让你得到你想要的:
means <- function(data, value){
value <- enquo(value)
data %>%
filter(Species == !!value) %>%
summarise(msl = mean(Sepal.Length), msw = mean(Petal.Width))
}https://stackoverflow.com/questions/53351140
复制相似问题