title: Find overlapping segments in multiple columns
body: <p>I have following data set and would like to get in a separate column the number of overlapping labels (<code>n.overlaps</code>), the name of the overlapping labels (<code>overlap.labels</code>) and also the duration of the overlap (<code>overlap.duration</code>). </p>
  
  <p>This is my data set:</p>
  
  <pre><code>label   begin   end
  ======================
  lower   9.03    12.41
  lower   28.773  29.975
  lower   33.895  35.992
  lower   46.814  48.854
  lower   58.51   61.51
  lower   62.971  63.491
  upper   28.132  30.432
  upper   46.716  50.82
  upper   58.536  61.482
  upper   29.975  33.895
  upper   53.376  54.08
  upper   10.358  11.958
  upper   30.532  46.716
  upper   51.633  58.536
  head    9.918   14.818
  head    29.823  30.623
  head    58.802  61.404
  head    61.404  63.562
  </code></pre>
  
  <p>The table, I would like to get would be this one:</p>
  
  <pre><code>lower.begin    lower.end    upper.begin     upper.end   head.begin  head.end    n.overlaps  overlap.labels       overlap.duration
  9.03           12.41         10.358         11.958        9.918      14.418         3        lower|upper|head         1.6
  28.773         29.975        28.132         30.432        29.823     30.623         3        lower|upper|head         0.152
  33.895         35.992        30.532         46.716         -            -           2        lower|upper              2.097
  ...
  </code></pre>
  
  <p>This is the visual representation of the table:</p>
  
  <p><a href="https://i.stack.imgur.com/V3qBD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/V3qBD.png" alt="enter image description here"></a></p>
  
  <h1>Data</h1>
  
  <pre><code>structure(list(label = c("lower", "lower", "lower", "lower", 
  "lower", "lower", "upper", "upper", "upper", "upper", "upper", 
  "upper", "upper", "upper", "head", "head", "head", "head"
  ), begin = c(9.03, 28.773, 33.895, 46.814, 58.51, 62.971, 28.132, 
  46.716, 58.536, 29.975, 53.376, 10.358, 30.532, 51.633, 9.918, 
  29.823, 58.802, 61.404), end = c(12.41, 29.975, 35.992, 48.854, 
  61.51, 63.491, 30.432, 50.82, 61.482, 33.895, 54.08, 11.958, 
  46.716, 58.536, 14.818, 30.623, 61.404, 63.562)), .Names = c("label", 
  "begin", "end"), class = "data.frame", row.names = c(NA, -18L))
  </code></pre>