title: Merge data.frame rows by consecutive index
body: <p>I have a <code>data.frame</code> of linear intervals, where each interval also has a numeric index:</p>
  <pre><code>df &lt;- data.frame(id = c(&quot;id1&quot;,&quot;id20&quot;,&quot;id7&quot;,&quot;id12&quot;,&quot;id15&quot;),
                   start = c(36, 41, 216, 234, 300),
                   end = c(21, 112, 263, 269, 340),
                   index = c(11, 12, 28, 29, 33))
  </code></pre>
  <p>Where <code>df</code> is sorted by <code>index</code> in ascending order.</p>
  <p>I want to merge each set of rows whose indices are consecutive into a single row, such that their <code>id</code> is concatenated by a <code>;</code>, <code>start</code> is the minimum <code>start</code> of the set, <code>end</code> is the maximum <code>end</code> of the set, and <code>index</code> is also the maximum <code>index</code> of the set.</p>
  <p>So for the example above the resulting merged <code>data.frame</code> will be:</p>
  <pre><code>merged.df &lt;- data.frame(id = c(&quot;id1;id20&quot;,&quot;id7;id12&quot;,&quot;id15&quot;),
                          start = c(36, 216, 300),
                          end = c(112, 269, 340),
                          index = c(12, 29, 33))
  </code></pre>
  <p>Any idea?</p>