How To Average Every 5 Rows In Knime?

for example, I have a series of data in time stamp. I want to average the features every 5 rows. any node in Knime with such function?

Hi @HY_Z
Do you mean Rolling Average?

You can do it with a ‘Moving Aggregation’ node. Defining a ‘forward’ window length == 5 in your case, and using Mean as aggregator for the column value…

These are the basics…


Hi @HY_Z

Like @gonhaddock mentions, what do you consider every 5 rows.

If you are meaning the average for batches of 5 rows, you can use a Chunk Loop for this with Rows per Chunk set to 5.

Within the loop, calculate the average with a node of choice. With a Cross Joiner you link the rows within the chunk with the average. After all chunks have been processed, the loop will output the full data set again.

For illustration purposes, I’m just using a bunch of sequential integers.

How To Average Every 5 Rows In Knime.knwf (27.6 KB)

Hope this helps!

1 Like

thanks for reply.
When applying rolling average, every step one row is moved down, and the new average is calculated accordingly.

What I want to do is just get average for every 5 rows. If I have 100 rows, then finally 20 points will be got.

Thanks a lot. I will try this way.

Hi @HY_Z

Then you can consider to indexing the rolling average in groups of 5 with a Math Formula node:

mod($$ROWINDEX$$, 5)

And afterwards filter out any desired index, or a Rule Engine to BLANK() the unwanted for the whole series.


1 Like

Thanks a lot. How to “indexing the rolling average in groups of 5 wit a Math Formula node”?

There is a moving average node. Have you tried it?

You can try a Window Loop Node, as it will allow to configure how many rows should be considered per loop. You can define the window size (5) and need to select also the step size (5) to achieve your desired result.

Screenshot 2022-07-22 at 23.20.55

1 Like

Thanks. I ever try “Moving average Node”. Its function is to calculate the average for Row1 to Row5, then Row2 to Row6, then Row3 to Row7…
it is different from my requirement.

Thank you. Will try this.

I tried this. It works.

That is interesting because I do not see any operation within the window. Math formula with the column mean inside the window could also work

But glad that you found a solution which works for you

1 Like

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