Learn R Programming

rje (version 1.9)

and0: Fast pairwise logical operators

Description

Fast but loose implementations of AND and OR logical operators.

Usage

and0(x, y)
or0(x,y)

Arguments

x,y

A logical or numeric vector.

Value

A logical vector of length max(length(x), length(y)) with entries x[1] & x[2] etc.; each entry of x or y is TRUE if it is non-zero.

Details

Returns pairwise application of logical operators AND and OR. Vectors are recycled as usual.

Examples

Run this code
# NOT RUN {
and0(c(0,1,0), c(1,1,0))

# }
# NOT RUN {
set.seed(1234)
x = rbinom(5000, 1, 0.5)
y = rbinom(5000, 1, 0.5)

# 3 to 4 times improvement over `&`
system.time(for (i in 1:5000) and0(x,y))
system.time(for (i in 1:5000) x & y)
# }

Run the code above in your browser using DataLab