Want to map over columns in a dataframe & perform t-tests with each column against a fixed column. Desired output would be a dataframe with each row(s) being t-test results - can use map_dfr
once mapping process ok
Dug into tidy eval, not sure if it's a tidy eval error - any help much appreciated!
(mtcars
as toy dataset)
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.
Following tidyeval guidance: https://tidyeval.tidyverse.org/dplyr.html Tried to see if quoting / unquoting was the issue, but no dice
# Abstract variables
test_data <- function(group_var) {
quote_var <- enquo(group_var)
data %>% compare_means(quote_var ~ cyl, data = mtcars)
}
Actually, it may just be about formula evaluation specifially:
Is it about formula evaluation? Test
as.formula()
Success!!
Couldn't get an example to work with
mtcars
but will re-post if I do