[R] Re: your mail

Thomas Lumley tlumley at u.washington.edu
Thu Aug 8 01:10:51 CEST 2002

On Wed, 7 Aug 2002, Jay Pfaffman wrote:

> I've got a table of 1 row per observation.
> 16 questions * n subjects * 4 classrooms (2 teachers * 2 conditions)
> I'd like to run some simple regressions that look something like this:
>   lm(length ~ elapsed)
> I'd like to do the regressions several times, split out by
> questionkey, student, class.  What I've been doing is using a series
> of which's to create new data sets (e.g. class1, class2, class3,
> class4) and running the regressions (or whatever) against each of
> those new data sets.  It seems that there should be better a way to do
> this.

Use by()

models<-by(data, list(student), function(thesedata)

will return a list of lm() objects.  You can use lapply() to get
information out of these, for example


returns a list of coefficient vectors or


binds the vectors into a matrix.  There's an example in help(by)


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