Hello,
I just started to learn Knime and am doing my first steps with data manipulation. In the Column Expression Node I want to add a new output column to a table. For the content I want to do an “if…else statement”:
existing column Gender has either “M” or “F” as a value
I want to add a new column Gender2 with the value “male” or “female” depending on the value of Gender
whatever I try, either Gender2 is filled with only “male” or “female” as a value
a = column(“Gender”)
b = " "
if (a = “F”)
b = “female”
else
b = “male”
I based the above code on one of the learning tutorials … but somehow it does not work as I want it. Please point me to my error. Thank you, Udo
In JavaScript operator for comparison is not one equal sign but two ==. One equal sign is assignment operator and that is reason why new column is always filled either with male or female cause if() is always true. Check this workflow example for simple If Else constructions with Column Expressions node:
Additionally here is decent JS tutorial/documentation site I frequently use/consult when dealing with it:
Thank you Ivan,
I appreciate your answer and clarification.
This is helpful and gives me even more input for
finding solutions to newbie’s problems on my own
Best wishes, Udo