Assess overlap from one set of intervals to another

Description

Asses overlap from intervals in one set to intervals in another set, and return the relevant indices.

Usage

1
2
3
## S4 method for signature 
## 'Intervals_virtual_or_numeric,Intervals_virtual_or_numeric'
interval_overlap(from, to, check_valid = TRUE)

Arguments

from

An "Intervals" or "Intervals_full" object, or a vector of class "numeric". Note! Prior to v. 0.11.1, this argument was called target.

to

An "Intervals" or "Intervals_full" object, or a vector of class "numeric". Note! Prior to v. 0.11.1, this argument was called query.

check_valid

Should validObject be called before passing to compiled code? This, among other things, verifies that endpoints are of data type "numeric" and the closed vector/matrix is appropriately sized and of the correct data type. (Compiled code does no further checking.)

Details

Intervals which meet at endpoints overlap only if both endpoints are closed. Intervals in to with NA endpoints are ignored, with a warning; in from, such intervals produce no matches. Intervals in either to or from which are actually empty have their endpoints set to NA before proceeding, with warning, and so do not generate matches. If eith to or from is a vector of class "numeric", overlap will be assess for the corresponding set of points.

Value

A list, with one element for each row/component of from. The elements are vectors of indices, indicating which to rows (or components, for the "numeric" method) overlap each interval in from. A list element of length 0 indicates no overlapping elements.

Note

If you want real (type == "R") intervals that overlap in a set of positive measure — not just at endpoints — set all endpoints to open (i.e., close(from) <- FALSE; closed(to) <- FALSE) first.

This function is now just a wrapper for which_nearest.

See Also

See which_nearest for details on nearby as well as overlapping intervals in to.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Note that 'from' contains a valid but empty interval.

to <- Intervals(
               matrix(
                      c(
                        2,  8,
                        3,  4,
                        5, 10
                        ),
                      ncol = 2, byrow = TRUE
                      ),
               closed = c( TRUE, FALSE ),
               type = "Z"
               )

from <- Intervals(
               matrix(
                      c(
                         2,  8,
                         8,  9,
                         6,  9,
                        11, 12,
                         3,  3
                        ),
                      ncol = 2, byrow = TRUE
                      ),
               closed = c( TRUE, FALSE ),
               type = "Z"
               )
rownames(from) <- letters[1:nrow(from)]

empty(to)
empty(from)

interval_overlap(from, to)

# Non-empty real intevals of size 0 can overlap other intervals.

u <- to
type(u) <- "R"

v <- Intervals_full( rep(3,4) )
closed(v)[2,] <- FALSE
v
empty(v)
size(v)

interval_overlap(v, u)

# Working with points

interval_overlap( from, c( 2, 3, 6, NA ) )

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.