Logical {bit}R Documentation

Boolean operators and functions

Description

Boolean negation, and, or and exclusive or.

Usage

## S3 method for class 'bit':
! x
## S3 method for class 'bit':
e1 & e2
## S3 method for class 'bit':
e1 | e2
## S3 method for class 'bit':
e1 == e2
## S3 method for class 'bit':
e1 != e2
xor(x, y)
## Default S3 method:
xor(x, y)
## S3 method for class 'bit':
xor(x, y)

Arguments

x a bit vector (or one logical vector in binary operators)
y a bit vector or an logical vector
e1 a bit vector or an logical vector
e2 a bit vector or an logical vector

Details

Binary operators and function xor can combine 'bit' objects and 'logical' vectors. They do not recycle, thus the lengths of objects must match. Boolean operations on bit vectors are extremely fast because they are implemented using C's bitwise operators. If one argument is 'logical' it is converted to 'bit'.
The xor function has been made generic and xor.default has been implemented much faster than R's standard xor. This was possible because actually boolean function xor and comparison operator != do the same (even with NAs), and != is much faster than the multiple calls in (x | y) & !(x & y)

Value

An object of class 'bit'

Author(s)

Jens Oehlschlägel

See Also

bit, Logic

Examples

  x <- as.bit(c(FALSE, FALSE, FALSE, NA, NA, NA, TRUE, TRUE, TRUE))
  yl <- c(FALSE, NA, TRUE, FALSE, NA, TRUE, FALSE, NA, TRUE)
  y <- as.bit(yl)
  !x
  x & y
  x | y
  xor(x, y)
  x != y
  x == y
  x & yl
  x | yl
  xor(x, yl)
  x != yl
  x == yl

[Package bit version 1.0-1 Index]