[R] Problem with differences between S+ and R in parsing output tables with $

Douglas Bates bates at stat.wisc.edu
Mon Dec 9 20:25:03 CET 2002


"RexBryan" <rexbryan1 at attbi.com> writes:

> R-wizards
> 
> I have successfully run with S+ a statistical power calculation for
> non-normal distributions as presented in M. Crawley's new book.  When I
> tried the newest version of R on the same code, the $ parse statement
> doesn't seem to retrieve the appropriate number from a table. Note that
> some of the cosmetic differences in the two tables have to be dealt with
> by the parser. Any ideas what's happening?
> REX
> 
> # Begin R -------------------------------------------------------------
> #
> > summary(aov(model))
>  
>              	Df 	Sum Sq 	Mean Sq 	F value 	Pr(>F)
> fa            	1   	11.1    	11.1  	0.9327 	0.3345
> Residuals   	698 	8279.3    	11.9
> 
> # R: ... trying to parse the table gives a NULL for the probability of
> F... 
> 
> > (summary(aov(model))$"Pr(>F)")[1]
> NULL
> 
> # End R ---------------------------------------------------------------

Hmm - that's a peculiar way of trying to extract the information but
if you really want to do it like that you should first use str() to
determine the structure of the returned value.  It turns out that the
value is a list and the first component of the list is a data frame
with one column labelled "Pr(>F)".


> str(summary(aov(model)))
List of 1
 $ :Classes anova  and `data.frame':	3 obs. of  5 variables:
  ..$ Df     : num [1:3] 3 5 15
  ..$ Sum Sq : num [1:3] 13445  1428   781
  ..$ Mean Sq: num [1:3] 4482  286   52
  ..$ F value: num [1:3] 86.11  5.49    NA
  ..$ Pr(>F) : num [1:3] 1.11e-09 4.55e-03       NA
 - attr(*, "class")= chr [1:2] "summary.aov" "listof"

This means you would need to put [[1]] before the $

> summary(aov(model))[[1]]$"Pr(>F)"
[1] 1.110419e-09 4.550074e-03           NA




More information about the R-help mailing list