[R] Remove names and more from list with capture.output()

Sverre Stausland johnsen at fas.harvard.edu
Tue Nov 15 05:49:55 CET 2011


Hi R users,

I end up with a list object after running an anova:

> lm(speed ~ 1 + dist + speed:dist, data = cars) -> Int
> lm(speed ~ 1 + dist, data = cars) -> NoInt
> anova(Int, NoInt) -> test
> test <- test[c("Df", "F", "Pr(>F)")][2,]
> is.list(test)
[1] TRUE
> test
  Df      F    Pr(>F)
2 -1 18.512 8.481e-05 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

I would like to use capture.output() when writing this information to
a text file, but I would like to only print the row, not the names (Df
     F    Pr(>F)), and not the significance codes. That is, I want the
text printed to my text file to be:

2 -1 18.512 8.481e-05 ***

Is there a way to do this?

Thanks
Sverre



More information about the R-help mailing list