Conditional insert of non-existent column/row

Dear KNIME users,

I am already trying 4th snippet node to cope with my problem, and it seems with no luck. The problem is very simple: my workflow calculates classification model statistics. Using Value counter node, I obtain the number of 0s and 1s observed in my subset. Then the stats are calculated accorrdingly, assuming that both values are available. In rare examples, there are either no 1s or no 0s at all, and in these cases my calculations are halted.

The normal table looks like:

rowID    count

0.0        20

1.0        10

So my question is: is there a way to conditionally insert new row / column(after transposing) with value 0 for all rows (in my case, always 1 row) if one of the rowIDs is not present? In all the snippets I tried implementing, there is always a problem with checking for existence of the columns I am making reference to in my code. For instance, the following Java code cannot be compiled due to "Invalid settings: No such column: 1.0":

Method body

Integer number = 0;
if($1.0$ != null) {
 number = $1.0$;
}
return number;
 

Is there a way to skip this check, or perhaps to reference the column in the native Java way, or other, KNIME-friendly way to check for existence of column "1.0"? If there was better documentation of the node, I would solve this problem myself but the internals of the snippet class are unknow to me to see how the available variables are referenced with these $something$.

Your help will be greatly appreciated

indykpol

If you are sure, that the transposed table indeed contains a column "1.0" then you can de-select "compile on close" in the Java Snippet node. If you then first execute the transpose node and after that the Java Snippet node it should work. Also executing the whole workflow should work.

Have you read carefully my post? The thing is that in some rare cases the column 1.0 is not existent. This code was supposed to account for that. This part:

if($1.0$ != null)

is supposed to check for that existence. But this style $1.0$ is internal to the snippet node. If there was a better documentation of the node, I would up the variable in the class itself and would be able to test the real variable, and not just the reference $1.0$ which may be not existent and there seems to be no way of testing that. Anyways, in R, there is a hash containing all variable names and it was straightforwardly possible there to solve the problem using just 1 node:

R<-R

print(names(R))
if (!("X1.0" %in% names(R)))
    R$"X1.0" = 0.0;

if (!("X0.0" %in% names(R)))
    R$"X0.0" = 0.0;
 

Maybe this will help someone in the future.

Cheers,

indykpol

I think you need the 'Add Empty Rows' node, which you can specify either number of rows to add, or the minimum number of rows in your table, and also what is put in each row.

Hope this helps,

Steve