LogicBit: Boolean operators and functions for class bit

Description Usage Arguments Details Value Author(s) See Also Examples

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## 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<c3><a4>gel

See Also

bit, Logic

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  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

OHDSI/bit documentation built on May 9, 2017, 3:30 p.m.