Dear All,
I have a data frame that contains several dependent variables and
independent variables. I would like to save the regression coefficients
after fitting each dependent variables (with the same independent
variables). How to write a loop to do it automatically? For example, I
have
mydata<- data.frame(x1=1:10, x2=(1:10)^2,
y1=2*c(1:10) + c(1:10)^2 + rnorm(10),
y2=10*c(1:10) + 3*c(1:10)^2 + rnorm(10))
# I want to perform the following
mod1<- summary(lm(y1~x1+x2, data="">
mod2<- summary(lm(y2~x1+x2, data="">
# then save the coefficients:
output <- rbind(mod1, mod2)
Question: how to write a loop to obtain the output?
Thank you for your help!
Peng Huang
|
|