Home > Software design >  How to get p-values only in significance test in R
How to get p-values only in significance test in R

Time:11-11

I m working on significance tests in R, especially wilcox.test. I check for example column A of my dataframe data.

wilcox.test(data$A, mu=3)

Afterwards I get a lot of data and text in the console. Is there a posibility to get only the p.value? I hope it will be a bit more clear, when I check the other columns too.

CodePudding user response:

The output is a list, so extract with $ or [[

out <- wilcox.test(data$A, mu=3)
out$p.value

We can get more info by checking the str

str(out)

If there are more columns, loop over the columns with lapply/sapply and extract the p.value

sapply(data[c("A", "B")], function(x) wilcox.test(x, mu = 3)$p.value)
  • Related