Message-ID: <loom.20090110T192806-24@post.gmane.org>
Date: 2009-01-10T19:34:05Z
From: Ben Bolker
Subject: Applying 'lm' in each group
Bhargab Chattopadhyay <bhargab_1 <at> yahoo.com> writes:
>
> Hi,
>
> ?I want to?do regression?in each group. I made the group the following way.
Now I want to run regression
> in each of the three groups..
> Suppose ,
> w
>
> Now if I write lm(yg~xg) then it won't work. Please advice how to proceed.
>
> Thanks in advance.
>
The one-liner is
mapply(function(x,y) lm(y~x,data=data.frame(x,y)),xg,yg,
SIMPLIFY=FALSE)
Perhaps easier to understand:
results <- list()
for (i in seq(along=xg)) {
results[[i]] <- lm(yg[[i]]~xg[[i]])
}
Ben Bolker