Knime routine similar to R groupby() and mutate()

So I’m trying to replicate some R code in Knime. Specifically the R function groupby() used with mutate().

The code is:

df %>% group_by(week) %>% mutate(max_date=max(date))

The results of this takes a data frame df and groups the rows by the week column and then passes it to mutate() where and additional column is created “max_date” that adds the largest date of each of the groupings by week to the row for each row in that week group.

So if you have an initial table:

image

The resulting table would look like this:

image

I guess I could just use an R snippet and duplicate the code, but my objective it to do it with knime. Mutate, in combination with groupby in R, will apply the actions to each group input to mutate. It’s a powerful capability and I can’t seem to duplicate it.

Any help would be appreciated.

Hi @navywings

See this example wf KNIMEroutine.knwf (28.1 KB)

Do a GroupBy on week to find the max date. And join this max date again to your original dataset.

gr. Hans

2 Likes