Calculating overlap of segments in chromosome data
I read the data in

a &lt;- read.delim(textConnection("Chromosome\tStart\tEnd
1\t0\t2420037
1\t2420037\t2522634
1\t2522634\t10794763
1\t10794763\t10925915
1\t10925915\t11280057"))

b &lt;- read.delim(textConnection("chr\tstart\tend\tvariantaccession\tvariantsubtype
1\t10001\t127330\tnsv7879\tGain+Loss
1\t10001\t846808\tdgv2n71\tGain
1\t10377\t177417\tdgv1e1\tComplex
1\t10377\t177417\tnsv428112\tGain
1\t10377\t1018704\tdgv3e1\tComplex
1\t10499\t177368\tesv27265\tGain+Loss"))


and then used the GenomicRanges package to efficiently find overlaps between the query "A" and subject "B".

library(GenomicRanges)
A &lt;- makeGRangesFromDataFrame(a)
B &lt;- makeGRangesFromDataFrame(b, keep.extra.columns=TRUE)
olaps &lt;- findOverlaps(A, B)


olaps is basically a two-column matrix, indicating which element(s) of A overlap the corresponding elements of B. In the invocation above A and B enter symmetrically, but could be re-ordered if there were restrictions on the type of overlap (argument type, e.g., all of B strictly within A). To find the extent of overlap, I looked at the parallel (element wise) intersection of each overlap

&gt; isect &lt;- pintersect(A[queryHits(olaps)], B[subjectHits(olaps)])
&gt; isect
GRanges with 6 ranges and 0 metadata columns:
      seqnames           ranges strand
         &lt;Rle&gt;        &lt;IRanges&gt;  &lt;Rle&gt;
  [1]        1 [10001,  127330]      *
  [2]        1 [10001,  846808]      *
  [3]        1 [10377,  177417]      *
  [4]        1 [10377,  177417]      *
  [5]        1 [10377, 1018704]      *
  [6]        1 [10499,  177368]      *
  ---
  seqlengths:
    1
   NA


I could then create a data.frame with whatever information I want, e.g.,

data.frame(query=queryHits(olaps), subject=subjectHits(olaps),
           olap_width=width(isect), 
           query_width=width(A)[queryHits(olaps)],
           variantaccession=B$variantaccession[subjectHits(olaps)])


This will be fast for millions of records in A and B. 

makeGRangesFromDataFrame is available in the current release version of the package, installed by default when using R-3.1. It's easy to make a GRanges 'by hand', e.g.,

A &lt;- with(a, GRanges(Chromosome, IRanges(Start, End)))
B &lt;- with(b, GRanges(chr, IRanges(start, end), variantaccession=variantaccession))