how to identify groups of consecutive numbers?

Here’s an example of a table having 10 rows with a column that contains an ordered list of numbers (1,2,3,4,8,9,10,15,16,17).

I need to output a table that lists consecutive value ranges, e.g. :
1-4
8-10
15-17

Any ideas?

Hi @bkrogman

Welcome to KNIME Forum. Yes I have an idea. I needed quite a few node to fix your problem. But at least I works…? See consecutive numbers.knwf (56.4 KB)
Screenshot from 2020-09-03 21-11-34
gr. Hans

1 Like

The simplest solution to use K-Mean node with 3 clusters. Then use Group by with Min and Max functions to get borders of clusters. And finally String manipulation node to get range as
you wish join(Min_B, " - ", Max_B)

2 Likes

Wow, works like a dream. Thank you!

2 Likes

Hello,

here is a solution with slightly less nodes. Trick is to use ROWINDEX from Rule Engine node to determine group.
consecutive numbers_ipazin.knwf (39.1 KB)

Welcome to KNIME Community @bkrogman!

Br,
Ivan

2 Likes

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