Hi, I have a table with 2 columns: age and gender.
I would like to replace all the values equal to zero or less than zero (for example all the wrong negative values) for the column age with NULL values.
Is there a way or a workaround for perform this sort of operation?
You can use the Rule Engine node to do this. If you define a rule like this:
$age$ > 0 => $age$
and use the Replace Column option for age, any age value less than or equal to zero will be replaced with NULLs, and the other values will be kept as-is.
If you have a static missing value pattern, you could use the Column Auto Type Cast node to set values to missing across columns without any looping at all.
If you needed to apply a rule as above, I think you could use the Column List Loop Start node to apply it columnwise.
Sometimes Rule Engine, Variables and Null values can be tricky. I have added an example where you could define your own replacement rules. Age gets replaced by NULL and gender by “NA”.
This is a great example - thanks so much! Variable looping is super useful and having the rules documented in a separate sheet brings a lot of transparency!
One thing I noticed was the age rule didn’t seem to replace the age <=0 with the _dummy_null column, I am not entirely sure why? The gender rule worked well. Thanks.
it is a problem with the loop, the results are not stored properly. I changed the loop, although I am not completely satisfied with the result it shows what could be done.