Code:
stat.test <- general %>%
wilcox_test(total_perMB ~ gender) %>%
add_significance()
stat.test
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.)
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