Displaying 1 result from an estimated 1 matches for "results7".
Did you mean:
results
2012 Jan 11
3
Accomplishing a loop on multiple columns
...)["r.squared"]
#To calculate R2 for column 91:
lm.modelobs91 <- lm(results6[,c(91)] ~ data$observed)
R2.91 <- summary(lm.modelobs91)["r.squared"]
But I think there has to be a method to do this automatically and not 91
times.
I tried to use a for loop:
###(length(C) = 91)
results7<-data.frame(lm.modelobs=rep(NA,length(C)))
for (i in (1:91))
{
results7$lm.modelobs[i] <- lm(results6[i] ~ data$observed)
R2.[i] <- summary(lm.modelobs[i])["r.squared"]
}
I also tried just to calculate results7$lm.modelobs[i] without directly
calculating r.squared but I also did...