Learn R Programming

evanverse (version 0.4.0)

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).

Examples

Run this code
x <- 1:5
combine_logic(x > 2, x %% 2 == 1)            # AND by default
combine_logic(x > 2, x %% 2 == 1, op = "|")  # OR logic
combine_logic(c(TRUE, NA), c(TRUE, TRUE), na.rm = TRUE)

Run the code above in your browser using DataLab