[R] finding out more about an object, e.g. lm

Sean O'Riordain sean.oriordain at gmail.com
Tue Jul 5 15:56:50 CEST 2005


I'm trying to use lm(y~x) amongst others in an automated way; I've
gone through the section on indexing in R-lang and I've looked MASS4. 
How do I find out more about the structure of the returned object?  In
perl I can look at object structure pretty-printed in the debugger -
is there an R equivalent?

I've used coef(lm(y~x))[[1]] and coef(lm(y~x))[[2]] to extract the
intercept;  but while summary(lm(y~x)) prints R-squared... it isn't
entirely obvious how to extract this value as a scalar.  ?lm doesn't
give me the information

by saying
unlist(summary(lm(y~x))) it prints

[1] 0.2673333

so now I can say
my.r.sq <- summary(lm(y~x))$r.squared

but is there a better way?  on my small lm model unlist(lm(y~x)) is a
pretty long list! :-)

Many thanks in advance,
Sean O'Riordain

More information about the R-help mailing list