[R] Help with accessing elements of a list

anthony staines anthony_staines at hotmail.com
Mon Feb 4 15:09:28 CET 2002


Hi,

As part of the analysis of a longitudinal study, I have a list, called wg, 
on R 1.3.1 for windows created as follows -

wg <- by(xx, xx$mrn, function(xx) lm(xx$maternal.wt ~ xx$gestation, 
data=xx))

xx is a data.frame, and so wg contains the results of 293 linear 
regressions, as lm objects.

Now what I want is to extract the 293 intercepts and regression coefficients 
as a vector, and do things with them - like examine their distributions.

>wg[[1]] gives

Call:
lm(formula = xx$maternal.wt ~ xx$gestation, data = xx)

Coefficients:
(Intercept)  xx$gestation
     61.3014        0.2886

>wg[[1]][[1]] gives

(Intercept) xx$gestation
   61.301422     0.288568

>wg[[1]][[1]][[2]] gives

[1] 0.288568

What I need to get is 293 of these in a vector. None of the obvious 
variations on

>wg[[1:293]][[1]][[2]] gives anything except -

Error: attempt to select more than one element

I've read the manuals, and selections of the reference manual without 
achieving wisdom. I'm fairly sure that this is a very easy question, but I 
can't work it out by myself - and my head now hurts. Any suggestions?

--
Anthony Staines
Please reply to my work e-mail address anthony.staines at ucd.ie

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list