Skip to content

Intersection of two sets of intervals

3 messages · jim holtman, Thomas Meyer

#
Stavros, you are quite correct -- I discovered that the hard way a 
little while ago when testing my two-line solution. Use of pmin/pmax 
don't handle, for instance, cases where more than one interval in one 
set is wholly contained by an interval in the other. (I have a 
mis-posted msg awaiting moderator approval in R-help with a concrete 
example.)

Your tip to check out the intervals pkg looks promising. FYI, there the 
general intersection is computed as the complement of the union of the 
complements, i.e. A*B = (A'+B')' , aka DeMorgan.

Thanks for the help,

-tom
On 4/15/2009 11:27 AM, Stavros Macrakis wrote:
#
Here is one way to find the overlaps:
[,1] [,2]
[1,]    1    3
[2,]    5   10
[3,]   13   24
[,1] [,2]
[1,]    2    4
[2,]    7   14
[3,]   20   30
+                end=over[(over[,2] == -1) & (over[, 3] == 1), 1])
start end
[1,]     2   3
[2,]     7  10
[3,]    13  14
[4,]    20  24

        
On Wed, Apr 15, 2009 at 12:06 PM, Thomas Meyer <tm35 at cornell.edu> wrote:

  
    
#
That does it perfectly -- and it's pretty much the same technique as 
used in the intervals pkg.

-tom
On 4/15/2009 12:43 PM, jim holtman wrote: