有人可以告诉我如何使用dplyr将带有参数名称的向量传递给函数吗?
library("dplyr", quietly = TRUE, warn.conflicts = FALSE) # version 0.8.0.1
# Does not work
iris %>% rowwise() %>% mutate(v1 = mean( as.name(names(iris)[-5]) ) )
iris %>% rowwise() %>% mutate(v1 = mean( !!(names(iris)[-5]) ) )
iris %>% rowwise() %>% mutate(v1 = mean( enquo(names(iris)[-5]) ) )
iris %>% rowwise() %>%
mutate(v1 = mean( c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width") ) )
# This works and is the intended result
iris %>% rowwise() %>%
mutate(v1 = mean( c(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width ) ) ) …Run Code Online (Sandbox Code Playgroud)