# Gather data points which are close together in time

I want to gather some data together based on how close together they are in time. Consider this list of numbers:

{1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, 100, 101, 102, 103, 104, 105, 110, 111, 112}


We can see that there a subsets of different lengths, and within each subset the points are separated by some amount -- in this case $$1$$.

I want to be able to gather or sort the elements together based on some separation threshold. For the example list I gave the result would be:

{{1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15}, { 50, 51, 52, 53}, {100, 101, 102, 103, 104, 105}, {110, 111, 112}}


My intent is to be able to group datasets together which are close in time. Normally if all of my datasets have the same length I would use partition and be done with it, however my subsets have different lengths so it makes sense to group by how close together they are in time.

• Split[{1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, 100, 101, 102, 103, 104, 105, 110, 111, 112}, Abs[#1 - #2] == 1 &] Mar 26, 2021 at 15:59
• Nice, can this be extended to deal with $x-y$ data? But still only sorting/splitting by the x data? Mar 26, 2021 at 16:08
• Ah yes I think one can: Split[Data[[All, {1, 2}]], Abs[#1[[1]] - #2[[1]]] < 100 &]  Mar 26, 2021 at 16:13

Split[Data[[All, {1, 2}]], Abs[#1[[1]] - #2[[1]]] < Thresh &]