I have a data.frame in R with columns of most types like this:
df <- data.frame(ID = c(1, 2, 3, 4),
Gender = c("Male", "Male", "Female", "Male"),
Average_Score_Test_1 = c(1.2,2.4,3.2,1.8),
Average_Score_Test_2 = c(3.2, 2.8, 1.7, 2.5),
Qualification = c("UG","UG","UG","PG")
)
though with thousands of columns and rows. I have several vectors of the names of groups of columns e.g.
DV_Type1 <- c("Average_Score_Test_1", "Average_Score_Test_2")
and the same for grouping variables
Type1_Group <- c("Gender", "Qualification")
I have then run a nested for loop that runs through the elements of each vector to run significance tests etc...
This runs perfectly for kruskal_test, e.g.
df %>%
kruskal_test(df[[DV_Type1[1]]] ~ df[[Type1_Group[1]]])
But with exactly the same code but with wilcox_test instead of kruskal_test I get
df %>%
wilcox_test(df[[DV_Type1[1]]] ~ df[[Type1_Group[1]]])
Error: Can't extract columns that don't exist. The column 'Type1_Group[1]' doesn't exist
Why is this not working?
Using Rstatix in order to get the results in a tibble.