[R] for loop question
Giovanni Petris
gpetris at definetti.uark.edu
Tue Sep 11 23:00:17 CEST 2001
It seems the expected behavior to me, given that the : operator has
higher precedence than +.
> j <- 1
> j+1:3
[1] 2 3 4
> From: "HEUMANN,JOHN (A-Loveland,ex1)" <john_heumann at agilent.com>
> Date: Tue, 11 Sep 2001 12:54:49 -0600
> Sender: owner-r-help at stat.math.ethz.ch
> Precedence: SfS-bulk
> Content-Type: text/plain;
> charset="ISO-8859-1"
> Content-Length: 1047
>
> 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 ????
> >
>
> Conversely, the following behaves as expected:
>
> > for (i in 1:2) {
> + k <- i+1
> + for (j in k:3) {
> + print(j)
> + }
> + }
> [1] 2
> [1] 3
> [1] 3
> >
>
> This is under NT4, SP5 using a pre-compiled binary from CRAN.
>
> Thanks,
> -jh-
>
--
__________________________________________________
[ ]
[ Giovanni Petris GPetris at uark.edu ]
[ Department of Mathematical Sciences ]
[ University of Arkansas - Fayetteville, AR 72701 ]
[ Ph: (501) 575-6324, 575-8630 (fax) ]
[ http://definetti.uark.edu/~gpetris/ ]
[__________________________________________________]
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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