[R] Loop doesn't work
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Tue Dec 1 15:58:00 CET 2009
On Tue, Dec 1, 2009 at 2:01 PM, Trafim <rdapamoga at 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
More information about the R-help
mailing list