interval-intersection

Intersecting ranges of consecutive values in logical vectors in R

跟風遠走 提交于 2020-01-14 10:23:29
问题 I have two logical vectors which look like this: x = c(0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0) y = c(0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0) I would like to count the intersections between ranges of consecutive values. Meaning that consecutive values (of 1s) are handled as one range. So in the above example, each vector contains one range of 1s and these ranges intersect only once. Is there any R package for range intersections which could help here? 回答1: I think this should work (calling your

A range intersection algorithm better than O(n)?

扶醉桌前 提交于 2019-12-17 15:29:01
问题 Range intersection is a simple, but non-trivial problem. Its has been answered twice already: Find number range intersection Comparing date ranges The first solutions is O(n) and the second solution is for a database (which is less than O(n) of course). I have the same problem, but for a large n and I am not within a database. This problem seems to be very similar to Store 2D points for quick retrieval of those inside a rectangle but I don't see how it maps. So what data structure would you

Overlapping time intervals WITHOUT for/while loops

你。 提交于 2019-12-12 02:24:35
问题 The best way to ask my question is via a clear example. Consider 2 timelines (e.g. time in seconds) A and B where the intervals for each timeline are: intervals_a = 0 1 1 4 4 7 7 9 intervals_b = 0 2 2 3 3 5 5 8 Notice that the first a-interval overlaps the first b-interval. The second a-interval overlaps the first, second, and third b-intervals, and so on. Ultimately, I need an output which shows the indices of a-intervals which overlap with b-intervals as below: output = 1 1 \\ 1st a

A range intersection algorithm better than O(n)?

南楼画角 提交于 2019-11-27 18:11:15
Range intersection is a simple, but non-trivial problem. Its has been answered twice already: Find number range intersection Comparing date ranges The first solutions is O(n) and the second solution is for a database (which is less than O(n) of course). I have the same problem, but for a large n and I am not within a database. This problem seems to be very similar to Store 2D points for quick retrieval of those inside a rectangle but I don't see how it maps. So what data structure would you store the set of ranges in, such that a search on a range costs less than O(n)? (Extra credit for using