Coercion from bit is quite fast because we use a double loop that fixes each word in a processor register.

# S3 method for class 'bit'
as.logical(x, ...)

# S3 method for class 'bit'
as.integer(x, ...)

# S3 method for class 'bit'
as.double(x, ...)

# S3 method for class 'bitwhich'
as.integer(x, ...)

# S3 method for class 'bitwhich'
as.double(x, ...)

# S3 method for class 'bitwhich'
as.logical(x, ...)

# S3 method for class 'ri'
as.logical(x, ...)

# S3 method for class 'ri'
as.integer(x, ...)

# S3 method for class 'ri'
as.double(x, ...)

# S3 method for class 'which'
as.logical(x, length = attr(x, "maxindex"), ...)

Arguments

x

an object of class bit(), bitwhich() or ri()

...

ignored

length

length of the boolean vector (required for as.logical.which)

Value

as.logical() returns a vector of FALSE, TRUE, as.integer() and as.double() return a vector of 0,1.

Author

Jens Oehlschlägel

Examples


  x <- ri(2, 5, 10)
  y <- as.logical(x)
  y
#>  [1] FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE
  stopifnot(identical(y, as.logical(as.bit(x))))
  stopifnot(identical(y, as.logical(as.bitwhich(x))))

  y <- as.integer(x)
  y
#>  [1] 0 1 1 1 1 0 0 0 0 0
  stopifnot(identical(y, as.integer(as.logical(x))))
  stopifnot(identical(y, as.integer(as.bit(x))))
  stopifnot(identical(y, as.integer(as.bitwhich(x))))

  y <- as.double(x)
  y
#>  [1] 0 1 1 1 1 0 0 0 0 0
  stopifnot(identical(y, as.double(as.logical(x))))
  stopifnot(identical(y, as.double(as.bit(x))))
  stopifnot(identical(y, as.double(as.bitwhich(x))))