Pairwise detect relationships between a vector and an iv
Source:R/vector.R
vector-detect-pairwise.Rd
This family of functions detects different types of relationships between a
vector and an iv pairwise. where pairwise means that the i-th value of x
is compared against the i-th value of y
. This is in contrast to
iv_between()
, which works more like base::%in%.
iv_pairwise_between()
detects if the i-th value ofx
, a vector, falls between the bounds of the i-th value ofy
, an iv.iv_pairwise_includes()
detects if the i-th value ofx
, an iv, includes the i-th value ofy
, a vector.
These functions return a logical vector the same size as the common size of
x
and y
.
Arguments
- x, y
[vector, iv]
For
iv_pairwise_between()
,x
must be a vector andy
must be an iv.For
iv_pairwise_includes()
,x
must be an iv andy
must be a vector.x
andy
will be recycled against each other.
Examples
x <- as.Date(c("2019-01-01", "2019-01-08", "2019-01-21"))
y <- iv_pairs(
as.Date(c("2019-01-01", "2019-01-03")),
as.Date(c("2019-01-07", "2019-01-09")),
as.Date(c("2019-01-18", "2019-01-21"))
)
x
#> [1] "2019-01-01" "2019-01-08" "2019-01-21"
y
#> <iv<date>[3]>
#> [1] [2019-01-01, 2019-01-03) [2019-01-07, 2019-01-09) [2019-01-18, 2019-01-21)
# Does the i-th value of `x` fall between the i-th interval of `y`?
iv_pairwise_between(x, y)
#> [1] TRUE TRUE FALSE
# Does the i-th interval of `y` include the i-th value of `x`?
iv_pairwise_includes(y, x)
#> [1] TRUE TRUE FALSE
a <- c(1, NA, NA)
b <- iv_pairs(c(NA, NA), c(3, 4), c(NA, NA))
# Missing intervals always propagate
iv_pairwise_between(a, b)
#> [1] NA NA NA
iv_pairwise_includes(b, a)
#> [1] NA NA NA