Skip to contents

Kleene logical AND: strong or weak

Usage

and(x, y, kleene_logic = c("strong", "weak"))

Arguments

x, y

Logical vectors (will be recycled if lengths differ).

kleene_logic

One of "strong" (default) or "weak".

  • "strong": R’s default three-valued AND; FALSE dominates.

  • "weak": propagate NA whenever either operand is NA.

Value

A logical vector of length max(length(x), length(y)).

Examples

# And operation with strong Kleene logic (default), same as `&`.
and(c(TRUE, FALSE, FALSE, NA), c(TRUE, TRUE, NA, NA))
#> [1]  TRUE FALSE FALSE    NA

# Weak Kleene logic (propagate `NA` even if other is `FALSE`).
and(c(TRUE, FALSE, FALSE, NA), c(TRUE, TRUE, NA, NA), kleene_logic = "weak")
#> [1]  TRUE FALSE    NA    NA