I'm trying to do a one-way anova on several row of a dataset and extract the p_value to use it afterwards.
Here's what i've done:
anova <- function(x) {summary(aov(x ~ bt.factor))[[1]]["Pr(>F)"]}
anv.pval <- apply(golubALL, 1, anova)
With this formula i'm able to extract the pvalue but it comes with other elements:
$`1414_at`
Pr(>F)
bt.factor 0.7871
Residuals
What I would like to have as a result is only this in a list. How could I extract it ?
Consider using broom
. With tidy()
, you can extract only the p.value
field:
require(broom)
a <- aov(mpg ~ wt, mtcars)
tidy(a)
# term df sumsq meansq statistic p.value
# 1 wt 1 847.7252 847.725250 91.37533 1.293959e-10
# 2 Residuals 30 278.3219 9.277398 NA NA
tidy(a)$p.value
# [1] 1.293959e-10 NA