intervals (version 0.15.1)

interval_overlap: 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

# S4 method for 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.)

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.

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.

See Also

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

Examples

Run this code
# NOT RUN {
# 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 ) )
# }

Run the code above in your browser using DataCamp Workspace