R: Summaries of boolean vectors

Summaries {bit} | R Documentation

## Summaries of boolean vectors

### Description

Fast aggregation functions for `booltype` vectors. namely `bit`, `all`, `any`, `anyNA`, `min`, `max`, `range`, `sum` and `summary`. Now all boolean summaries (except for `anyNA` because the generic does not allow it) have an optional `range` argument to restrict the range of evalution. Note that the boolean summaries have meaning and return values differing from logical aggregation functions: they treat `NA` as `FALSE`, `min`, `max` and `range` give the minimum and maximum positions of `TRUE`, `summary` returns counts of `FALSE`, `TRUE` and the `range`. Note that you can force the boolean interpretation by calling the booltype method explicitely on any `booltypes` input, e.g. `min.booltype()`, see the examples.

### Usage

    ## S3 method for class 'bit'
    all(x, range = NULL, ...)

    ## S3 method for class 'bit'
    any(x, range = NULL, ...)

    ## S3 method for class 'bit'
    anyNA(x, recursive = FALSE)

    ## S3 method for class 'bit'
    sum(x, range = NULL, ...)

    ## S3 method for class 'bit'
    min(x, range = NULL, ...)

    ## S3 method for class 'bit'
    max(x, range = NULL, ...)

    ## S3 method for class 'bit'
    range(x, range = NULL, ...)

    ## S3 method for class 'bit'
    summary(object, range = NULL, ...)

    ## S3 method for class 'bitwhich'
    all(x, range = NULL, ...)

    ## S3 method for class 'bitwhich'
    any(x, range = NULL, ...)

    ## S3 method for class 'bitwhich'
    anyNA(x, recursive = FALSE)

    ## S3 method for class 'bitwhich'
    sum(x, range = NULL, ...)

    ## S3 method for class 'bitwhich'
    min(x, range = NULL, ...)

    ## S3 method for class 'bitwhich'
    max(x, range = NULL, ...)

    ## S3 method for class 'bitwhich'
    range(x, range = NULL, ...)

    ## S3 method for class 'bitwhich'
    summary(object, range = NULL, ...)

    ## S3 method for class 'which'
    all(x, range = NULL, ...)

    ## S3 method for class 'which'
    any(x, range = NULL, ...)

    ## S3 method for class 'which'
    anyNA(x, recursive = FALSE)

    ## S3 method for class 'which'
    sum(x, range = NULL, ...)

    ## S3 method for class 'which'
    min(x, range = NULL, ...)

    ## S3 method for class 'which'
    max(x, range = NULL, ...)

    ## S3 method for class 'which'
    range(x, range = NULL, ...)

    ## S3 method for class 'which'
    summary(object, range = NULL, ...)

    ## S3 method for class 'booltype'
    all(x, range = NULL, ...)

    ## S3 method for class 'booltype'
    any(x, range = NULL, ...)

    ## S3 method for class 'booltype'
    anyNA(x, ...)

    ## S3 method for class 'booltype'
    sum(x, range = NULL, ...)

    ## S3 method for class 'booltype'
    min(x, range = NULL, ...)

    ## S3 method for class 'booltype'
    max(x, range = NULL, ...)

    ## S3 method for class 'booltype'
    range(x, range = NULL, ...)

    ## S3 method for class 'booltype'
    summary(object, range = NULL, ...)

    ## S3 method for class 'ri'
    all(x, range = NULL, ...)

    ## S3 method for class 'ri'
    any(x, range = NULL, ...)

    ## S3 method for class 'ri'
    anyNA(x, recursive = FALSE)

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

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

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

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

    ## S3 method for class 'ri'
    summary(object, ...)

### Arguments

`x` | an object of class bit or bitwhich
`range` | a `ri` or an integer vector of length==2 giving a range restriction for chunked processing
`...` | formally required but not used
`recursive` | formally required but not used
`object` | an object of class bit

### Details

Summaries of `bit` vectors are quite fast because we use a double loop that fixes each word in a processor register. Furthermore we break out of looping as soon as possible. Summaries of `bitwhich` vectors are even faster, if the selection is very skewed.

### Value

as expected

### Author(s)

Jens Oehlschlägel

### See Also

`length`

### Examples

      l <- c(NA, FALSE, TRUE)
      b <- as.bit(l)

      all(l)
      all(b)
      all(b, range=c(3,3))
      all.booltype(l, range=c(3,3))

      min(l)
      min(b)

      sum(l)
      sum(b)

      summary(l)
      summary(b)
      summary.booltype(l)

[Package bit version 4.0.4 Index]