for j=i+1 inside for i loop

Hi, what is the best approach to do an operation to all unique pairs of (row) entries in a table excluding x vs. x operation?

It`s the typical

for i=0; do

......for j=i+1; do

loop.

I tried using two "Row entry to Variable" nodes but that didnt seem to work, also I was not sure how to simulate the j=i+1 part, to only get unique pairs, and no entry combined with itself.

I try to give an example, the following table (1 column)

A

B

C

should lead to this table (2 columns)

A B

A C

B C

Thanks!

 

 

Does Cross Join solve this for you or do you only need unique combinations (with AB being the same as BA).  If the later, you might be able to do something fishy with Distance Matrix Calculate > Distance Matrix Pair Extractor > Some Joins.  

 

Interesting problem. Here's one approach...

1) Collect all the values from the list into a comma-delimited String variable. This is done using the GroupBy node with no groupby columns (see attached workflow). Select aggregations to create the comma-delimited list as well as the unique count. Follow with a TableRow To Variable node.

2) Next calculate the number of combinations expected using a Java Edit Variable node, using the count of unique items from the list. Next create an empty table with the number of rows equal to the number of calculated combinations using the Empty Table Creator node.

3) Finally use a Java Snippet node to construct your loop within a loop and populate the empty table using the comma-delimited string containing the list items (first parse it into an array for convenience).

The attached workflow does everything except calculate the number of combinations (step 2) and implement the code to populate the table with combinations (step 3).

If you know Java this should be fairly easy to implement (google for an efficient calculation for num combinations). If you don't know java, post the calculation for num combos (and the pseudocode for enumeration of combinations), and I'll post back the java code.

Note that if you have other columns in your original table that you want to keep, you can use a Joiner node to re-introduce them to the table produced by this workflow.

Good luck

Don