combine_logic: combine_logic: Combine multiple logical vectors with a logical operator
Description
A utility function to combine two or more logical vectors using
logical AND (&) or OR (|) operations. Supports NA handling and
checks for consistent vector lengths.
Usage
combine_logic(..., op = "&", na.rm = FALSE)
Value
A single logical vector of the same length as inputs.
Arguments
...
Logical vectors to combine.
op
Operator to apply: "&" (default) or "|".
na.rm
Logical. If TRUE, treats NA values as TRUE (default is FALSE).
x <- 1:5combine_logic(x > 2, x %% 2 == 1) # AND by defaultcombine_logic(x > 2, x %% 2 == 1, op = "|") # OR logiccombine_logic(c(TRUE, NA), c(TRUE, TRUE), na.rm = TRUE)