R: Boolean operators and functions for class bit

LogicBit {bit} | R Documentation

## Boolean operators and functions for class bit

### Description

Boolean 'negation', 'and', 'or' and 'exclusive or'.

### Usage

    ## S3 method for class 'bit'
    !x
    ## S3 method for class 'bitwhich'
    !x
    ## S3 method for class 'bit'
    e1 & e2
    ## S3 method for class 'bitwhich'
    e1 & e2
    ## S3 method for class 'bit'
    e1 | e2
    ## S3 method for class 'bitwhich'
    e1 | e2
    ## S3 method for class 'bit'
    e1 == e2
    ## S3 method for class 'bitwhich'
    e1 == e2
    ## S3 method for class 'bit'
    e1 != e2
    ## S3 method for class 'bitwhich'
    e1 != e2
    xor(x, y)
    ## Default S3 method:
    xor(x, y)
    ## S3 method for class 'bit'
    xor(x, y)
    ## S3 method for class 'bitwhich'
    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'.

Binary operators and function `xor` can combine 'bitwhich' objects and other vectors. They do not recycle, thus the lengths of objects must match. Boolean operations on bitwhich vectors are fast if the distribution of TRUE and FALSE is very asymetric. If one argument is not 'bitwhich' it is converted to 'bitwhich'.

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' (or 'bitwhich')

### 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

      x <- as.bitwhich(c(FALSE, FALSE, FALSE, NA, NA, NA, TRUE, TRUE, TRUE))
      yl <- c(FALSE, NA, TRUE, FALSE, NA, TRUE, FALSE, NA, TRUE)
      y <- as.bitwhich(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.1-15 Index]