Sorter in Column List Loop

Hi,

I have a table with 4 columns and I would like to sort all of them in Ascending order.

So I created a worflow with

ColumnListLoopStart --> Sorter (with FlowVariable    Incllist 0 = CurrentColumnName)  --> LoopEnd(ColumnAppend)

 

The intermediate results of the loop seems correct but the final result is not sorted in ascending order.

What's wrong?

Thanks in advance

Regards

The problem is you need to sort the columns before they are placed into the loop. 

The easiest way without need to loop to sort a table by column is to transpose the table and sort by the RowKey. You can then transpose back. The attached workflow shows this as an example. The columns start off sorted in ascending order, so I've flipped it to descending.

Best

David

 

 

 

 

Thank you David. Sorry but I think that my question was not clear enough.

I have a table with 4 columns:

 

col1 col2 col3 col4
b dd ddd aaaa
c aa bbb bbbb
a cc ccc dddd
d bb aaa cccc

 

And I would like to sort the content of each column in ascending order to get this result:

 

col1 col2 col3 col4
a aa aaa aaaa
b bb bbb bbbb
c cc ccc cccc
d dd ddd dddd

 

So I created a worflow with:

ColumnListLoopStart --> Sorter (with FlowVariable    Incllist 0 = CurrentColumnName)  --> LoopEnd(ColumnAppend)

 

The intermediate results of the loop seems correct but the final result is not sorted in ascending order.

What's wrong?

Thanks in advance

Regards

 

My apologies I mis-understood

The issue is with the RowID. This is the unique key for any table within Knime. Consequently, when the loop end is collecting the resutls, it will resort the data from each iteration to align the RowID. The result is you'll not see the sorted order within the loop.

The solution is to use the RowID node (Row -> Other -> RowID) to redefine the ids for each iteration after the sorting and before passing them to the Loop End. This allows you to modify the alignment of the columns absolutely in terms of the newly sorted order, and the Loop End will collate them in order for you.

Have a look at the attached workflow. 

Best

David

 

I guess not many people like to restructure their tables instead of looping but the node sequence Unpivot->Rank->Pivot also works nicely for this case :-)

Unfortunately, Pivot has the quirky behaviour of adding "+ColumnNames" to the end each pivoted column name, which can be removed by Column Rename (Regex). Without this behaviour, it would be a perfect alternative.

Thank you very much