Skip to content
Prev 164129 / 398506 Next

for loop query

Hi,
It is. It runs out of bounds with j > 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