| vector-detect | R Documentation |
This family of functions detects different types of relationships between a
vector and an iv. It works similar to base::%in%, where needles[i]
checks for a match in all of haystack.
iv_between() detects when needles, a vector, falls between the
bounds in haystack, an iv.
iv_includes() detects when needles, an iv, includes the values
of haystack, a vector.
This function returns a logical vector the same size as needles containing
TRUE if the value in needles matches any value in haystack and FALSE
otherwise.
iv_between(needles, haystack, ..., missing = "equals")
iv_includes(needles, haystack, ..., missing = "equals")
needles, haystack |
For For
|
... |
These dots are for future extensions and must be empty. |
missing |
Handling of missing values in
|
A logical vector the same size as needles.
Locating relationships
Locating relationships between a vector and an iv
Pairwise detect relationships between a vector and an iv
x <- as.Date(c("2019-01-05", "2019-01-10", "2019-01-07", "2019-01-20"))
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
# Detect if the i-th location in `x` is between any intervals in `y`
iv_between(x, y)
# Detect if the i-th location in `y` includes any value in `x`
iv_includes(y, x)
# ---------------------------------------------------------------------------
a <- c(1, NA)
b <- iv(c(NA, NA), c(NA, NA))
# By default, missing values in `needles` are treated as being exactly
# equal to missing values in `haystack`, so the missing value in `a` is
# considered between the missing interval in `b`.
iv_between(a, b)
iv_includes(b, a)
# If you'd like to propagate missing values, set `missing = NA`
iv_between(a, b, missing = NA)
iv_includes(b, a, missing = NA)
# If you'd like missing values to be treated as unmatched, set
# `missing = FALSE`
iv_between(a, b, missing = FALSE)
iv_includes(b, a, missing = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.