tags:

views:

107

answers:

2

Is there a simple way of performing an operation on all possible pairs of rows in a table?

For example, if I had four rows, I would want the operation to be applied to rows 1 and 2, 1 and 3, 1 and 4, 2 and 3, 2 and 4, and finally rows 3 and 4.

A: 

what kind of operation? give us an example.

Hassan Voyeau
For reference: that's not an answer; seems more like it belongs in a comment to me.
Shane
A: 

Nested loops seem like the easiest way to me.. unless you have some special requirement?

for (i = 0; i < 3; i++) {
  for (j = i + 1; j < 4; j++) {
    operation(row[i], row[j]);
  }
}
Carl Norum
I think hatorade wanted R code, not C code. See the R tag.
Rob Hyndman
Seems strange he would accept the answer then, but good call on the tag.
Carl Norum
eh, i'm competent enough to get the idea
hatorade