Sean Davis
2005-Sep-02 13:17 UTC
[R] Finding all overlaps between two sets of 1-Dimensional regions
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? Thanks, Sean
Dimitris Rizopoulos
2005-Sep-02 14:05 UTC
[R] Finding all overlaps between two sets of 1-Dimensional regions
maybe something like this could work in your case: set1 <- t(apply(matrix(rnorm(20), 10, 2), 1, sort)) set2 <- t(apply(matrix(rnorm(10), 5, 2), 1, sort)) ######################## set1. <- apply(set1, 1, rev) apply(set2, 1, function(x) apply(set1. <= x, 2, any)) I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Sean Davis" <sdavis2 at mail.nih.gov> To: "r-help" <r-help at stat.math.ethz.ch> Sent: Friday, September 02, 2005 3:17 PM Subject: [R] Finding all overlaps between two sets of 1-Dimensional regions>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? > > Thanks, > Sean > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Charles C. Berry
2005-Sep-04 01:21 UTC
[R] Finding all overlaps between two sets of 1-Dimensional regions
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