I have a collection that has different data type versions of the same attribute. The attribute is present as a numeric in some elements in the collection and as a nominal in other elements. But it is really the same attribute (which should be a nominal data type). I want to Append the collection together (since it is the same set of attributes in all cases) but of course it won't let me until all the data types are the same.
The question is how can I use Loop Collection and change all the data types for this attribute to nominal? Using Numerical to Nominal fails because it won't work when the attribute is already nominal. Likewise, I tried Generate Attributes using the str() and/or eval() functions but it also fails when it encounters a version of the attribute which is the wrong data type.
I'm thinking I should be able to do something like this with Branch but I can't seem to find a condition based on data type. Or maybe there's another way to do this that I haven't thought of? Any help is appreciated!
Solved! Go to Solution.
if you have only two possible attribute types, you could try solving it with the "Handle Exception" operator within the loop. E.g. putting in the "Numerical to Polynomial" operator on the "Try" side and just making the connection on the "Catch" side. If you have more than two possible attribute types, I think it should be possible to add yet another "Handle Exception" on the "Catch" side. I have never tried that though.
you do a Loop Attributes with the Numerical filter type and convert the actual numericals based on their name (for example) inside that loop.
It wouldn't act on the nominals if they already have the correct type.
exactly what I was going to suggest, @FBT. Loop Examples or Loop Values with Handle Exception and then append. If the append is causing you grief, you can use the always-very-handy Union Append building block that was posted a while ago.
Thanks for all the ideas! As usual, there are multiple solutions with RapidMiner and your thoughts were all helpful. I ended up with a simpler workflow by using a single Numerical to Nominal filtered by value type inside a Loop Collections operator---it solved my problem by turning all numerics into nominals, which I could undo after the Append by using Parse Numbers on ones that I wanted to turn back into numerics.