[R] Help with accessing elements of a list

Thomas Lumley tlumley at u.washington.edu
Mon Feb 4 17:36:46 CET 2002


On Mon, 4 Feb 2002, anthony staines wrote:

> 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))

It would be slightly more elegant (but equivalent) to write
 wg <- by(xx, xx$mrn, function(xx) lm(maternal.wt ~ 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.
>

Well, if you had one of these you would use coef(one.of.these) to get the
coefficients, so given an entire list you could use
   sapply(wg,coef)
to return the 293x2 matrix of coefficients.

	-thomas

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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