The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here
More than 3 argument If condition, eg: if, elseif, elseif, else...
memecross89
Member Posts: 2 Learner I
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!
0
Best Answers
-
rjones13 Member Posts: 204 UnicornHi @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 -
memecross89 Member Posts: 2 Learner I@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