How to extract first unique value till the next unique value is encountered?

Dear Knime users,

I am using Knime 2.8.1 and I want to perform a column operation, whose contents are, for example as following:

A
A
A
B
B
C
C
C
A
A

 

 

 

 

 

 

 

 

 

 

 

The desired output is:

A
B
C
A

 

 

 

 

 

So basically, what I want to do is to extract the first character and then wait for the next new character, extract it and so on. The problem is that, for example, as you see in the above table that A occurs in two different places, but it's uniqueness considered only once when I use RowID.
Is there any node that could perform such an operation?

Thank you in advance for your help.

 

Best regards

Rohit

Java snippets are probably your friend here.

In the imports section:

import java.util.arraylist;

In the custom declarations:

ArrayList<String> myValues = new ArrayList<String>();

String lastVal = "";

And in the main code:

if (!c_testcol.equals(lastVal)){
//Deal with a new value
lastVal=c_testcol;
myVals.put(lastVal);
}

c_outCol=myVals.toArray(new String[0]);  //Collection columns need arrays not Collections

You need to set up the snippet so the c_testcol refers to your input column of interest, and c_outCol to a new Array column for the output.

Now, the last row in the output table will contain a collection cell with the output you require, so use a Snippet Row filter with

return (ROWNO==(ROWCOUNT-1)); //Check the exact words here - they will be in the dialog

to keep only the last row (NB you need ROWCOUNT-1 because ROWNO starts at 0), and then an ungroup node to turn the collection back into a new column.

Hope that makes sense, and does the trick,

Steve

Wouldn't the "group by" node work in this case? 

The "GroupBy" node would work if you wanted truly unique values.  But in this case the task is to keep the value only if it is different from the value in the previous row.

The "Lag Column" node is useful in this context --- it will create a new column which you can offset from the current column by one row.  Then you can use the "Rule Engine" to designate each row's value as New (if different from the previous value) or Old (if it is the same as the previous value), followed by filtering out only the New values.

You may use GroupBy without any grouping columns and Unique concatenate as value, then split back the newly created single cell into columns using Cell Splitter.