is.flanked: Is a vector element surrounded by certain values?

View source: R/vector_tools.R

is.flankedR Documentation

Is a vector element surrounded by certain values?

Description

Checks if an element in a vector is flanked, i.e. if the elements before and after it are %in% a vector of candidates.

Usage

is.flanked(vec, items, edges_as_na = TRUE)

Arguments

vec

(Vector) A vector.

items

(Vector) A vector.

edges_as_na

(Logical) If TRUE (default), the computation will add NA to the start and end of vec temporarily. If FALSE, it will reuse the first and last values. See examples.

Value

A Logical vector of the same length as vec.

Authors

Examples

test_vec <- c(1, NA, 2, NA, 3, 4, NA, 5)

is.flanked(test_vec, items = c(NA), edges_as_na = TRUE)

# The edges are regarded as flanked by `NA` because `edges_as_na == TRUE` adds `NA` to
# the start and end of `vec`.
#> [1]  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE


is.flanked(test_vec, items = c(NA), edges_as_na = FALSE)

#> [1] FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE


DesiQuintans/desiderata documentation built on April 9, 2023, 5:43 a.m.