Reputation: 11
I'm still learning R and I need some advice regarding very simple matter.
for (i in 1:6) {
model.i = lm(data1[,i+1] ~ data1[,"mkt"]+data1[,"riskfree"])
print(summary(model(i)))
print(anova(model(i)))
}
I want to make six different simple linear regression, and assign different linear regressions to different names; like model.1, model.2, model.3......
But what I wrote there doesn't work as I expected. I would appreciate your help.
Thanks
Upvotes: 0
Views: 62
Reputation: 44525
Put them in a list:
lapply((1:6), function(i) lm(data1[,i+1] ~ data1[,"mkt"]+data1[,"riskfree"]))
It's much easier.
Upvotes: 2