More than 3 argument If condition, eg: if, elseif, elseif, else...
memecross89
New Altair Community Member
How can I have more than 3 arguments in an if condition when trying to generate a new attribute "Generate Attribute" operator?
Such as:
or if(Age < 2, "Baby" || Age < 12, "Child" || Age < 19, "Teen" || Age < 30, "Adult" || Age <= 65, "Adult" || Age > 65, "Senior")
For a new column name "AgeGroup" based on an existing Attribute "Age" which just has numerical integer values of instances (people's) age...
I'd rather have everything in one Operator, or use the least amount of operators possible to keep things clean!
Such as:
if(Age < 2, "Baby" || Age < 12, "Child")
&& if(Age < 19, "Teen" || Age < 30, "Adult")
&& if(Age <= 65, "Adult" || Age > 65, "Senior")
or if(Age < 2, "Baby" || Age < 12, "Child" || Age < 19, "Teen" || Age < 30, "Adult" || Age <= 65, "Adult" || Age > 65, "Senior")
For a new column name "AgeGroup" based on an existing Attribute "Age" which just has numerical integer values of instances (people's) age...
I'd rather have everything in one Operator, or use the least amount of operators possible to keep things clean!
Tagged:
0
Best Answers
-
Hi @memecross89,
The way I generally get around this is to nest another if statement, I.e:
if(condition, true action, if(condition, true action, else))
Hopefully this should keep it fairly simple for you application.
Best,
Roland1 -
@rjones13
I was able to create a working if condition for my "Generate Attribute" operator.
Thanks for confirming that "The way I generally get around this is to nest another if statement, I.e:
if(condition, true action, if(condition, true action, else))"
works, at first I tried this before I made this thread. But it seems I forgot an else condition at the end which was giving me an error.
Here it is, adding "NK" at the end fixed my issues:if(Age < 2, "Baby",
if(Age < 12, "Child",
if(Age < 19, "Teen",
if(Age < 30, "Adult",
if(Age <= 65, "Adult",
if(Age > 65, "Senior", "NK"))))))0
Answers
-
Hi @memecross89,
The way I generally get around this is to nest another if statement, I.e:
if(condition, true action, if(condition, true action, else))
Hopefully this should keep it fairly simple for you application.
Best,
Roland1 -
@rjones13
I was able to create a working if condition for my "Generate Attribute" operator.
Thanks for confirming that "The way I generally get around this is to nest another if statement, I.e:
if(condition, true action, if(condition, true action, else))"
works, at first I tried this before I made this thread. But it seems I forgot an else condition at the end which was giving me an error.
Here it is, adding "NK" at the end fixed my issues:if(Age < 2, "Baby",
if(Age < 12, "Child",
if(Age < 19, "Teen",
if(Age < 30, "Adult",
if(Age <= 65, "Adult",
if(Age > 65, "Senior", "NK"))))))0