[R] regression, for loop

yiping.fan@syngenta.com yiping.fan at syngenta.com
Tue Apr 30 18:23:14 CEST 2002


Hello, all
   Here are the questions I have:
data samples:
 Data          style  x   y
data1   r       2   3
data1   r       3  4
data1   r       4 5
data1   g      4  5
data1  g      6  7
data1  g     6   7
data2  r    8  9
data2  r     8  9
data2  r     8   9
data2  g     8    9 
data2  g      8   9
data2   g   8    9
...
datan


we have n data  (data1 - datan).  For each data, I want to do a simple
regression:
y ~ x+style
I am using a for loop now
for(i in 1:n){
   data.name=Data[i];
   res<-lm(y~x+style, data, subset=(Data == data.name) )
}  

I am wondering whether it is possible to do the same without using for loop?
Also,  after regression, I am only interested in getting  the P value for
style, how to extract it?

Thank you very much!
 
          Best regards,

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