# How can I transform all my Columns in order that they have only binary values?

Dear everybody,

I have some data I try to transform in a way that they only have the values 0 and 1. I already found a way doing that in the Rule engine node using
\$columnname\$ >1 =>1
How can I make a Loop or something similar to do that for all columns without making a rule engine for every single variable?

Lisa

Hi there!

There is Column List Loop Start node that iterates over a list of columns:

Inside this loop you can have Rule Engine node and at the end Loop End (Column Append) node. To be honest not sure you will get proper results like this but feel free to try and get to know various KNIME nodes. What you can use instead of Rule Engine node is Column Expressions node which is pretty mighty node and might be more useful in your case.

Alternatively if you are dealing with number type columns (which I would assume as you are using greater operator) you can use Math Formula (Multi Column) node. It enables you to evaluate same mathematical expression for a set of selected columns and there is if() function

If you will have any problems/questions just drop a message back here

Br,
Ivan

2 Likes

Thanks a lot!

I found a way using Column List Loop Start, Column Rename Regex, renaming every Column “column”, using the rule engine and renaming it back with Column Rename regex. Then ending the Loop.

Could that be a job for the One to Many node?

Hi @mlauber71 !

Not really. One to Many only takes nominal columns and creates multiple columns out of one depending on number of unique values in it. Also rule is fixed - equal.

For this problem you have an input like
col1 col2
100 200
200 400
300 600
400 800
500 1000

and you want to have 1 where ever cell is bigger than 350 for example. So output would be:
col1 col2
0 0
0 1
0 1
1 1
1 1

Hope this helps

Br,
Ivan

1 Like