Re: [R] Accomplishing a loop on multiple columns

2012-01-12 Thread Nerak
Many thanks! Never used lists before, but it’s a great solution! It works very well! Although, I have a next question concerning this. I want to know for which value (column) I have the maximal Rsquared. Therefore, I unlist the LIST so that it’s written like a vector. The columns were always na

Re: [R] Accomplishing a loop on multiple columns

2012-01-12 Thread Nerak
I just saw a little mistake in my last post: Totally in the end, last line of the last loop, results$depth[,u] [t-1] should be results$newdepth[,u] [t-1]. My apologies. for (u in 1:91) { results$newdepth [,u]<- results$depth [,u] for (t in 2:60) { results$newdepth[,u][t] <- results$newdepth[,u] [t

Re: [R] Accomplishing a loop on multiple columns

2012-01-11 Thread iliketurtles
Lists are the answer. LIST<-list() for(i in 1:ncol(results6)) { LIST[[i]]<-lm(results6[,i]~data$observed) } You'll now have a 91 entry list of lm(). You can then do something like this: LIST2<-list() for(i in 1:length(LIST)) { LIST2[[i]]<-LIST[[i]]$r.squared } This should now be a li