[SOLVED] Multiply a whole table with one value

Hi!

I'm a beginner with knime. I have the following problem:

there is a table, I want to multiply with a faktor (wich, right now is in a table with only one column and one row). The table is a Pivot-table and looks like this:

Types Valueclass 1  Valueclass 2  Valueclass3

Typ A     value1a          value2a          value3a

Typ B     value1b          value2b          value3b

Typ C     value1c          value2c          value3c

I simply want to multiply every value with the factor. Is there any way to do this?

Thanks a lot for helping!

if you only have 3 columns, I would just the "math node" three times, with the factor as a workflow variable so you can just do "$Valueclass1$ * workflowvariable"

If you have more columns, you could create a loop over the columns...

you can have a look at the example server for an example on looping over columns and changing them...

knime://EXAMPLES/06_Control_Structures/04_Loops/03_Looping_over_all_columns_and_manipulation_of_each

I have 8 columns, so Math node is not really an option.

A loop is a good idea. Is it possible to input the factor within the loop? because the factor I use is computed in knime and I have to be able to update it. So I can't just type it in the Math-node.

I've been looking for other solutions and (because I know R a bit) I used the R Snippet, with the following code (I added the factor as a column in a join before the R Snippet):

col1 <- matrix(knime.in$"column1")
col2 <- matrix(knime.in$"column2")
col3 <- matrix(knime.in$"column3")

Fac <- matrix(knime.in$"factor")

 Columns <- cbind(col1, col2, col3)
Facvector <- as.vector(Fac)
Col_neu <- Columns * Facvector

colnames(Col_fin) <- c("column1", "column2", "column3")

knime.out <- Col_fin

 

It works, but I think a loop would be more elegant, because R seems to be a bit slow.

Thanks a lot!

PS: your link to the loop-example doesn't seem to work.

that link to the loop example is indeed not a useable link, but shows you the path in the EXAMPLES server you have in the Knime explorer.

You can just have your factor transformed into a variable (with a "table row to variable" node) and use it in the math node...

oh, this both makes sense :D thanks!

One more question: How do I use the column rename (regex) node? I know I need it, to rename the columns to be able to use the math node multible times. But somehow I'm not able to change the full name of the column. All I can do is change the parts, that are the same in the column names anyways:

Column_1  column_2  column_3

=> newname1  newname2  newname3

Well, I don't think you need to change anything in that node. As it is in the example, it has some "dummy" column name in the "Search string (regexp)" field ("Universe_0_0")'; in fact, that field is controlled by the workflow variable "currentColumnName" which is spit out by the "Column List Loop Start" node.

So, for each column in the "TOP" part of the "Column splitter" node it will rename the column to "ANONYMOUS_COLUMN" just for the sake of the "Math formula" node and then it will rename that column to its original name...

your right :) thanks a lot!