[R] Finding all overlaps between two sets of 1-Dimensional regions

Charles C. Berry cberry at tajo.ucsd.edu
Sun Sep 4 03:21:01 CEST 2005


On Fri, 2 Sep 2005, Sean Davis wrote:

> I have a simply defined regions ([start,end] where start<end).  I have two
> large sets of them and want to find all regions in the first that overlap
> any regions in the second.  The closest I could find by searching is
> overlap.owin in I can do this by looping, but there is likely a better way
> to do this.  Any suggestions?


findInterval can be helpful and fast for larger problems

Say s1,e1 (>0) are the starts and ends of your first set and s2,e2 (>0) 
are for the second and are in order according to s2 .

I think this is what you need to get going:

s2.0 <- c(0, s2) # if any s1 < any s2, this is needed
e2.0 <- c(0, e2)

s1.in.int <- s1 <= e.2.0 [ findInterval( s1, s2.0 ) ]
e1.in.same.int <- e1 <= e.2.0 [ findInterval( s1, s2.0 ) ]

e1.in.any.int <- e1 <= e.2.0 [ findInterval( e1, s2.0 ) ]

Caveat: Possible typos above

Chuck

>
> Thanks,
> Sean
>
>
>

Charles C. Berry                        (858) 534-2098
                                          Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	         UC San Diego
http://biostat.ucsd.edu/~cberry/         La Jolla, San Diego 92093-0717




More information about the R-help mailing list