[R] What is wrong with this FOR-loop?

Serguei Kaniovski kaniovsk at wifo.ac.at
Mon Dec 5 12:47:54 CET 2005


Hi, I have a more complex example, but the problem boils down to this 
FOR-loop not filling in the res-matrix

run_rows<-seq(0,1,0.05)
run_cols<-seq(0.3,0.6,0.05)

res<-matrix(NA,length(run_rows),length(run_cols))

for(i in run_rows)
{
     for(j in run_cols)
     {
         res[i,j]=i+j
         #niether the above, nor res[[i,j]]=i+j work, why?
     }
}

Thank you,
Serguei




More information about the R-help mailing list