[R] for loop question

Duncan Murdoch murdoch at stats.uwo.ca
Tue Sep 11 22:48:47 CEST 2001


On Tue, 11 Sep 2001 12:54:49 -0600, you wrote in message
<9153F74610B7D311B83900902771C8710A4CE336 at axcs07.cos.agilent.com>:

>In the windows version of R (1.3.0) is the following a bug, a
>known problem, or expected behavior:
>
> > for (i in 1:2) {
> + for (j in i+1:3) {
> + print(j)
> + }
> + }
> [1] 2
> [1] 3
> [1] 4      ????
> [1] 3
> [1] 4      ????
> [1] 5      ????

I think you're fooled by operator precedence.  The expression "i+1:3"
is equivalent to "i + (1:3)", i.e. c(i+1, i+2, i+3).

Duncan Murdoch
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list