relation-detect | R Documentation |
This family of functions detects different types of relationships between
two ivs. It works similar to base::%in%, where needles[i]
checks for
a relationship in all of haystack
.
iv_overlaps()
detects a specific type
of overlap between the two ivs.
iv_precedes()
detects if needles[i]
precedes (i.e. comes before) any
interval in haystack
.
iv_follows()
detects if needles[i]
follows (i.e. comes after) any
interval in haystack
.
These functions return a logical vector the same size as needles
containing
TRUE
if the interval in needles
has a matching relationship in
haystack
and FALSE
otherwise.
iv_overlaps(needles, haystack, ..., type = "any", missing = "equals") iv_precedes(needles, haystack, ..., missing = "equals") iv_follows(needles, haystack, ..., missing = "equals")
needles, haystack |
Interval vectors used for relation matching.
Prior to comparison, |
... |
These dots are for future extensions and must be empty. |
type |
The type of relationship to find. One of:
|
missing |
Handling of missing intervals in
|
A logical vector the same size as needles
.
Locating relationships
Detecting relationships pairwise
Locating relations from Allen's Interval Algebra
library(vctrs) x <- iv_pairs( as.Date(c("2019-01-05", "2019-01-10")), as.Date(c("2019-01-07", "2019-01-15")), as.Date(c("2019-01-20", "2019-01-31")) ) y <- iv_pairs( as.Date(c("2019-01-01", "2019-01-03")), as.Date(c("2019-01-04", "2019-01-08")), as.Date(c("2019-01-07", "2019-01-09")), as.Date(c("2019-01-10", "2019-01-20")), as.Date(c("2019-01-15", "2019-01-20")) ) x y # Does each interval of `x` overlap `y` at all? iv_overlaps(x, y) # Which intervals of `y` are within an interval in `x`? iv_overlaps(y, x, type = "within") # --------------------------------------------------------------------------- a <- iv(c(1, NA), c(2, NA)) b <- iv(c(NA, NA), c(NA, NA)) # Missing intervals are seen as exactly equal by default, so they are # considered to overlap iv_overlaps(a, b) # If you'd like missing intervals to be treated as unmatched, set # `missing = FALSE` iv_overlaps(a, b, missing = FALSE) # If you'd like to propagate missing intervals, set `missing = NA` iv_overlaps(a, b, missing = NA)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.