I have a matrix (but for the purposes of the example I will simplify to a vector).
I want to loop over all pairs of the list. So if the list is length n (or the matrix has n columns), the resulting list has to be (n choose 2) items long.
Suppose n = 6 for the example, but in reality is 36.
Basically, I want a loop like this:
list=1:6
endlist= vector("list", 15) # 15 from 6!/((4!)(2!))
Here is what I want:
Note the below loop does NOT work since there is no i index, and there appears to be no linear combination of j and k that fits the index. Is there a nonlinear one? Or is there a better way to program this?
for(j in 1:5){
for(k in (j+1):6){
endlist[[i]]=list[j]*list[k]
}
}
Giving the output:
endlist=
[[1]]
[1] 2 3 4 5 6
[[2]]
[1] 6 8 10 12
etc.