[R] Loop doesn't work
Hi everybody, I have the following problem, the following code seems to run only once for i and j and for k from one to M. Doesn't R for increase the argument by itself? for (i in 1:N){ for (j in 1:(Tk-1)){ if((XGrid[i] Xk[j+1])(Xk[j] = XGrid[i])){ for (k in 1:M){ if ((RBins[k]=Rk[j+1])(Rk[j+1]RBins[k+1])){ GR[k] - +1 } } } } } Thanks a lot [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loop doesn't work
On Tue, Dec 1, 2009 at 2:01 PM, Trafim rdapam...@gmail.com wrote: Hi everybody, I have the following problem, the following code seems to run only once for i and j and for k from one to M. Doesn't R for increase the argument by itself? for (i in 1:N){ for (j in 1:(Tk-1)){ if((XGrid[i] Xk[j+1])(Xk[j] = XGrid[i])){ for (k in 1:M){ if ((RBins[k]=Rk[j+1])(Rk[j+1]RBins[k+1])){ GR[k] - +1 } } } } } Of course it does. Try this, which is something we call a complete reproducible example: N=10 for(i in 1:N){ print(i) } How do we know your N isn't 1 and your Tk isn't 2? Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loop doesn't work
Thanks a lot! I was afraid smth is wrong with my R syntaxis. On Tue, Dec 1, 2009 at 3:58 PM, Barry Rowlingson b.rowling...@lancaster.ac.uk wrote: On Tue, Dec 1, 2009 at 2:01 PM, Trafim rdapam...@gmail.com wrote: Hi everybody, I have the following problem, the following code seems to run only once for i and j and for k from one to M. Doesn't R for increase the argument by itself? for (i in 1:N){ for (j in 1:(Tk-1)){ if((XGrid[i] Xk[j+1])(Xk[j] = XGrid[i])){ for (k in 1:M){ if ((RBins[k]=Rk[j+1])(Rk[j+1]RBins[k+1])){ GR[k] - +1 } } } } } Of course it does. Try this, which is something we call a complete reproducible example: N=10 for(i in 1:N){ print(i) } How do we know your N isn't 1 and your Tk isn't 2? Barry [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.