I am doing a number of regression's using a for loop, and want to store the results in a list. Normally, I would use assign:
AllChicks <- levels(ChickWeight$Chick) #example database
for (i in AllChicks) {
DataSub <- subset(ChickWeight, Chick==i)
Fit <- lm(DataSub$Time ~ DataSub$weight)
assign(paste("Regr_",i,sep=""),Fit)
assign(paste("Sum_",i,sep=""),summary(Fit))
assign(paste("Residual_",i,sep=""),residuals(Fit))
}
But now i would like to put the Fit, summary and Residuals in a list per Chick, so named Chick1, Chick2, Chick3 etc. I have found the following commands to work for the first object:
assign(paste("Chick",i,sep=""),list(Fit))
do.call("<-",list(paste("Chick",i,sep=""),list(Fit)))
But then off course the first list object is overwritten by:
assign(paste("Chick",i,sep=""),list(summary(Fit)))
And I've tried these, but they make a variable named "Chick1[[2]]", in stead of taking the second object from the list.
assign(paste("Chick",i,"[[2]]",sep=""),list(summary(Fit)))
do.call("<-",list(paste("Chick",i,"[[2]]",sep=""),list(summary(Fit))))
I have a feeling it must be very simple, but can't figure it out...