# Duplicate rows with a specific multiplier

Hello,

is there a possibility do duplicate a row or rather multiply by a specific number from the table?
For example i have a table like this:

In the end it should look like this:

so the row should be duplicated as often as the factor in Col2 indicates and if Col2 is for example LIKE 2 there should be the same Row for 2 times.
It is important that the 2 should then be divided by itself in the output table. (Col2 must always be 1)

I hope this is reasonably understandable

Hi Knimer17,

you can do this e.g. with two nested loops:

The Chunk Loop Start iterates the input rows one-by-one. Then I extract the “number of repetitions” using a flow variable in the Table Row to Variable which is fed into the second Counting Loop Start node. Both loops need to be terminated using a Loop End node.

At the end, I replace all `column2` values with a constant of 1 using the Rule Engine:

You can get the workflow from my NodePit Space:

Does this help?

Philipp

2 Likes

HI there @Knimer17,

welcome to KNIME Community!

Well you can take advantage of One Row to Many node to avoid loops. After it simply use Math Formula to get 1s in your column.

Here is example wf:
2020_02_17_RowMultiplication2.knwf (12.4 KB)

Br,
Ivan

4 Likes

Hello Philipp,

Maybe you could look at my reply below to Ivan, it is a bit more complicated than I thought.

Maybe you can find a solution to my problem

Many thanks.

Hello Ivan,

Forgot to say that my input table is a bit more complicated. It looks like this

In the end it should look like this:

So all rows of Col2 should be divided by the first number (in red: 1,3,2) if Col1 stays the same. So the rows with x’s remain because they will be divided by one. The lines with Y are divided by 3, so from the previous 3 lines a total of 9 lines.

A bit hard to explain but I hope you can understand.

Best regards

1 Like

Hi Knimer,

for this case you’ll most definitely need some nested loops. I suggest you have a look at the WF which I posted and see how this can be adapted to your case.

Beside the Loop nodes which I already used, I’d recommend to have a look at the Group Loop Start node.

Bonne chance!
Philipp

Never worked with loops in my knime career (has started not even 3 weeks ago).

So it will be hard but I’ll give it a try and keep you guys updated.

Hi @Knimer17,

possibly this workflow do the same without looping. The only assumption is, that your data are in the correct order and the multiplication of the rows is performed on the first row for each unique entry in Col1 (group condition).

BR
Hermann DEMO.knwf (71.8 KB)

3 Likes

Hi @morpheus,

thanks, already found a similiar solution as yours, not as difficult as I thought.

BR
Knimer17

2 Likes

Hi @Knimer17,

sometimes you don’t see the wood for the trees.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.