title: Is there any way to do clustering or sorting of file according to two numeric range value columns?
body: <p>I have a big file and I try to find a way to do sorting or do clustering of the data according to two numeric columns that are in a range of numbers, but I could not find correct or fit function regarding my question. Could you please someone how knows help me.<br />
  Thanks in advance.</p>
  <p>My file is like this sample file but very big and as you see in this example, first and second rows are like alternating numbers (I mean without any gap in between (sequence number)) and also third and forth rows are like that, but rows fifth and sixth are different and actually far from eachother. Therefore, I want to consider first and second as a one cluster, third and forth as a one cluster, fifth and sixth as a two different clusters to have at the end 4 rows instead of 6 rows because rows 1,2 and 3,4 are in one range without any gap in between.<br />
  Example file:</p>
  <pre><code>df &lt;- setDT(data.frame(name = c(&quot;chr1&quot;, &quot;chr1&quot;, &quot;chr1&quot;, &quot;chr1&quot;,&quot;chr1&quot;,&quot;chr1&quot;), 
    start = c(8480001, 8480251, 10006251, 10006501,13910501,14841751), 
    end = c(8480250, 8480500, 10006500, 10006750,13910750,14842000),
    length = c(250, 250, 250, 250,250,250))) 
  </code></pre>
  <p>Expected output:</p>
  <pre><code>output &lt;- setDT(data.frame(name = c(&quot;chr1&quot;, &quot;chr1&quot;, &quot;chr1&quot;, &quot;chr1&quot;),
    start = c(8480001, 10006251, 13910501, 14841751), 
    end = c(8480250, 10006500, 13910750, 14842000), 
    length = c(250, 250, 250, 250))) 
  </code></pre>
  <p>In output, just I want to have first row of those rows that are in one cluster for example just row 1 for 1 and 2.</p>
  <p>Thanks again.</p>