| iv-set-pairwise {ivs} | R Documentation |
Pairwise set operations
Description
This family of functions performs pairwise set operations on two ivs.
Pairwise refers to the fact that the i-th interval of x is going to be
compared against the i-th interval of y. This is in contrast to their
counterparts, like iv_set_union(), which treat the entire vector of x
as a single set to be compared against all of y.
The descriptions of these operations are the same as their non-pairwise counterparts, but the ones here also have a number of restrictions due to the fact that each must return an output that is the same size as its inputs:
For
iv_pairwise_set_complement(),x[i]andy[i]can't overlap or abut, as this would generate an empty complement.For
iv_pairwise_set_union(),x[i]andy[i]can't be separated by a gap. Useiv_pairwise_span()if you want to force gaps to be filled anyways.For
iv_pairwise_set_intersect(),x[i]andy[i]must overlap, otherwise an empty interval would be generated.For
iv_pairwise_set_difference(),x[i]can't be completely contained withiny[i], as that would generate an empty interval. Additionally,y[i]can't be completely contained withinx[i], as that would result in two distinct intervals for a single observation.For
iv_pairwise_set_symmetric_difference(),x[i]andy[i]must share exactly one endpoint, otherwise an empty interval or two distinct intervals would be generated.
Usage
iv_pairwise_set_complement(x, y)
iv_pairwise_set_union(x, y)
iv_pairwise_set_intersect(x, y)
iv_pairwise_set_difference(x, y)
iv_pairwise_set_symmetric_difference(x, y)
Arguments
x, y |
A pair of interval vectors. These will be cast to the same type, and recycled against each other. |
Value
An iv the same size and type as x and y.
See Also
The non-pairwise versions of these functions, such as
iv_set_union().
Examples
x <- iv_pairs(c(1, 3), c(6, 8))
y <- iv_pairs(c(5, 7), c(2, 3))
iv_pairwise_set_complement(x, y)
z <- iv_pairs(c(2, 5), c(4, 7))
iv_pairwise_set_union(x, z)
# Can't take the union when there are gaps
try(iv_pairwise_set_union(x, y))
# But you can force a union across gaps with `iv_pairwise_span()`
iv_pairwise_span(x, y)
iv_pairwise_set_intersect(x, z)
# Can't take an intersection of non-overlapping intervals
try(iv_pairwise_set_intersect(x, y))
iv_pairwise_set_difference(x, z)
# The pairwise symmetric difference function is fairly strict,
# and is only well defined when exactly one of the interval endpoints match
w <- iv_pairs(c(1, 6), c(7, 8))
iv_pairwise_set_symmetric_difference(x, w)