Skip to content
Prev 144838 / 398500 Next

Help on nested FOR loops

Hey Philip,

I'm not sure if I understand what your "x11", "x12", etc. are.  You can 
combine the values of your two vectors using the expand.grid function. 
There is no need to do nester FOR loops:

 > i=c(1,2,3,4,5)
 > j=c(1,2,3)
 > x=expand.grid(i,j)
 > print (x)

    Var1 Var2
1     1    1
2     2    1
3     3    1
4     4    1
5     5    1
6     1    2
7     2    2
8     3    2
9     4    2
10    5    2
11    1    3
12    2    3
13    3    3
14    4    3
15    5    3

Hope this helps,

Julian
Philip Twumasi-Ankrah wrote: