Worik R | 1 Sep 2009 02:31
Picon

Is this a bug?

This programme

for(T in 1:3){
  for(j in 1:(5-1)){
    for(k in (j+1):5){
      for(l in (j+2):5){
        print(paste("1 JKL:", j,k,l,sep=" "))
      }
    }
  }
}

Prints out (among other things)
[1] "1 JKL: 4 5 6"

That is for(l in (j+2):5) sets l to 6 one more than the upper limit.

cheers
Worik

	[[alternative HTML version deleted]]

David Winsemius | 1 Sep 2009 02:46
Picon

Re: Is this a bug?


On Aug 31, 2009, at 8:31 PM, Worik R wrote:

> This programme
>
> for(T in 1:3){
>  for(j in 1:(5-1)){
>    for(k in (j+1):5){
>      for(l in (j+2):5){
>        print(paste("1 JKL:", j,k,l,sep=" "))
>      }
>    }
>  }
> }
>
> Prints out (among other things)
> [1] "1 JKL: 4 5 6"
>
> That is for(l in (j+2):5) sets l to 6 one more than the upper limit.

Except try this at the console and see if enlightenment occurs:

6:5

The second entry in n:m may not be an upper limit.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

(Continue reading)

Achim Zeileis | 1 Sep 2009 02:45
Picon

Re: Is this a bug?

Answer: No.

On Tue, 1 Sep 2009, Worik R wrote:

> This programme
>
> for(T in 1:3){
>  for(j in 1:(5-1)){
>    for(k in (j+1):5){
>      for(l in (j+2):5){
>        print(paste("1 JKL:", j,k,l,sep=" "))
>      }
>    }
>  }
> }
>
> Prints out (among other things)
> [1] "1 JKL: 4 5 6"
>
> That is for(l in (j+2):5) sets l to 6 one more than the upper limit.

Check out help(":") which explains that in from:to from is the starting 
value and to is the end value. Note that it does not impose that
from <= to or that to is the upper limit.

For j = 4, you get l to be in 6:5.
Z

> cheers
> Worik
(Continue reading)


Gmane