Message-ID: <200812091320.04835.cbeleites@units.it>
Date: 2008-12-09T12:20:04Z
From: Claudia Beleites
Subject: for loop query
In-Reply-To: <200812091143.mB9Bhbi6027384@hypatia.math.ethz.ch>
Hi,
> Why isn't my loop incrementing i - the outer loop to 2 and then resetting
> j=3?
It is. It runs out of bounds with j > 26
> Am I missing something obvious?
> > for (i in 1:25)
> + {
> + for (j in i+1:26)
You miss parentheses.
i + 1 : 26 is i + (1 : 26) as the vector 1 :26 is calculated first
what happens is that for i = 1 j goes over 2 : 27, with i = 2 over 3 : 28, ...
what you want is (i + 1) : 26:
for (i in 1 : 25)
for (j in (i + 1) : 26)
cat (i, j, "\n")
HTH Claudia
--
Claudia Beleites
Dipartimento dei Materiali e delle Risorse Naturali
Universit? degli Studi di Trieste
Via Alfonso Valerio 6/a
I-34127 Trieste
phone: +39 (0 40) 5 58-34 47
email: cbeleites at units.it