Outputting only p-value for ANOVA in R I'm doing some basic one-way ANOVA in R. It would be useful to be able to output only the p-value associated with a specific term without producing the whole ANOVA table (unrelated reason). I need the value as a basic numeric and not an ANOVA object For example, if I'm looking at anova(lm(yield~variety+block)) and just want the p-value for "variety", is there a straightforward way? Thanks!
 A: anova like almost all other functions in R, creates an object. Many data analysis functions create a named list of pieces of information, some of which is displayed and possibly other parts for use by other functions.
See str(anova(lm(yield~variety+block))) to get a sense of what's there.
As it stands, anova outputs a named list. The list element with the p-values can be accessed by name, anova(lm(yield~variety+block))$"Pr(>F)", or by element number, anova(lm(yield~variety+block))[[5]]. Either gives you a vector with all the p-values.
You appear to want the first one of those, element [1]. So
anova(lm(yield~variety+block))$"Pr(>F)"[1], or 
anova(lm(yield~variety+block))[[5]][1] should do it.
Note that str says it's a data frame (which is a special kind of list you can treat a bit like a matrix), so you can also do this: anova(lm(yield~variety+block))[1,5], which is probably the easiest of all.
(There are a number of other ways of accessing a particular element of a vector that's a particular element of a list, which should also work.)
If you want to play with the whole anova table, you should assign it to a variable:
aa <- anova(lm(yield~variety+block))

and then you can pull out whatever you want:
aa[1,5]

You can then rename or replace parts of it, to make it look however you need - but if you change it in substantial ways, you may want to remove the 'anova' class in case it no longer meets the requirements to be an anova table.
