RichardLang wrote:
> 
> I've just started using R last week and am still scratching my head.
> 
> I have a data set and want to run a separate regression across each level
> of a factor (treating each one separately). The data right now is arranged
> such that the value of the factor along which I want to "split" my data is
> one column among many.
> Best way to do this?
> 
> Thanks!
> 

You can check out lmList function in the nlme package, or more crudely:

lmfun <- function(d) { lm(y~x,data=d) }
myLmList <- lapply(split(mydata,splitfactor),lmfun)

even more compactly/confusingly:

myLmList <- lapply(split(mydata,splitfactor),lm,formula=y~x)

  good luck
   Ben Bolker


-- 
View this message in context: 
http://www.nabble.com/Noobie-question%2C-regression-across-levels-tp21020222p21021025.html
Sent from the R help mailing list archive at Nabble.com.

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

Reply via email to