wilcox_test problem

Hi I have a problem with applying the wilcox test.
Here is my data:

stat.test <- general %>%
wilcox_test(total_perMB ~ gender) %>%
I've been trying to run and then i had a error:
Error in UseMethod("wilcox_test") : **
** no applicable method for 'wilcox_test' applied to an object of class "data.frame"

I don't know whats wrong.

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.)


# 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

Thank you so much for all your help :hugs:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.