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 ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.