1

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 ?

andrew_reece
  • 20,390
  • 3
  • 33
  • 58
Solal
  • 13
  • 4
  • Add [[1]] between ] } and see the output. Is all about the positions in summary output so will be usefull to have data so we can replicate the output. – n1tk May 21 '18 at 02:47

1 Answers1

6

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
andrew_reece
  • 20,390
  • 3
  • 33
  • 58