[R] for loop doesn't stop with upper loop value
Hong Ooi
Hong.Ooi at iag.com.au
Wed Jul 4 02:21:03 CEST 2007
_______________________________________________________________________________________
lower+2 : upper parses as lower + (2:upper). The colon operator has
fairly high precedence. What you want is (lower + 2):upper
--
Hong Ooi
Senior Research Analyst, IAG Limited
388 George St, Sydney NSW 2000
+61 (2) 9292 1566
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of
Alexander.Herr at csiro.au
Sent: Wednesday, 4 July 2007 10:01 AM
To: r-help at stat.math.ethz.ch
Subject: [R] for loop doesn't stop with upper loop value
Hi list,
could anyone please educate me on the following:
lst<-seq(47, 239, by=12)
for(n in lst)
{
lower=n; upper=lower+10
for(i in lower+2 : upper)
{
print(paste(n, " i: ", i, " lower: ",lower, " upper :", upper))
}
}
does not stop when i = upper
A while loop fixes this but, I still don't understand why the for loop
doesn't stop when I has the value of upper
for(n in lst)
{
lower=n; upper=lower+10
while(lower !=upper +1)
{
print(paste(n, " lower: ",lower, " upper :", upper))
lower=lower+1
}
}
Any enlightment would be most welcome.
Thankx
Herry
______________________________________________
R-help at stat.math.ethz.ch 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.
_______________________________________________________________________________________
The information transmitted in this message and its attachme...{{dropped}}
More information about the R-help
mailing list