Skip to contents

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 of x, a vector, falls between the bounds of the i-th value of y, an iv.

  • iv_pairwise_includes() detects if the i-th value of x, an iv, includes the i-th value of y, a vector.

These functions return a logical vector the same size as the common size of x and y.

Usage

iv_pairwise_between(x, y)

iv_pairwise_includes(x, y)

Arguments

x, y

[vector, iv]

For iv_pairwise_between(), x must be a vector and y must be an iv.

For iv_pairwise_includes(), x must be an iv and y must be a vector.

x and y will be recycled against each other.

Value

A logical vector the same size as the common size of x and y.

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