wilcox_test problem

The pipe operator (%>%) passes whatever is on its left side as the first argument for the function on its right side and if you check the documentation for the wilcox_test() function, its first argument is x, a numeric vector of data values. A data frame is not a valid input.

I think you actually want to pass the general data frame as the data argument for the wilcox_test() function but with the pipe operator you will need to name all your arguments and use the . place holder, see this example: (Since you are not providing sample data in a copy/paste friendly format, I will exemplify using made-up data.)

library(dplyr)

# Made up version of your general data frame
general <- data.frame(
    total_perMB = rnorm(10),
    gender = sample(c(1,0), 10, replace = TRUE)
)

# Relevant code
general %>% 
    wilcox.test(formula = total_perMB ~ gender, data = .)
#> 
#>  Wilcoxon rank sum exact test
#> 
#> data:  total_perMB by gender
#> W = 15, p-value = 0.6095
#> alternative hypothesis: true location shift is not equal to 0

Created on 2022-05-17 by the reprex package (v2.0.1)

Note: Next time please provide a proper REPRoducible EXample (reprex) illustrating your issue.

1 Like