想要映射数据框中的列并针对固定列对每列执行 t 检验。所需的输出将是一个数据框,每行都是 t 检验结果 - 可以使用map_dfr
一次映射过程
深入研究 tidy eval,不确定这是否是 tidy eval 错误 - 非常感谢任何帮助!
(mtcars
作为玩具数据集)
library(rstatix)
# Test single cases - good
compare_means(mpg ~ cyl, data = mtcars)
compare_means(disp ~ cyl, data = mtcars)
compare_means(hp ~ cyl, data = mtcars)
# Trial map - fail
mtcars %>%
map(~compare_means(.x ~ cyl, data = mtcars))
Error: Can't subset columns that don't exist.
x Column `.x` doesn't exist.
遵循 tidyeval 指导:https ://tidyeval.tidyverse.org/dplyr.html 尝试查看是否引用/取消引用是问题,但没有骰子
# Abstract variables
test_data <- function(group_var) {
quote_var <- enquo(group_var)
data %>% compare_means(quote_var ~ cyl, data = mtcars)
}