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
explicitly on any booltypes input, e.g. min.booltype(), see the
examples.
# 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, ...)an object of class bit or bitwhich
a ri() or an integer vector of length == 2 giving a
range restriction for chunked processing
formally required but not used
formally required but not used
an object of class bit
as expected
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.
l <- c(NA, FALSE, TRUE)
b <- as.bit(l)
all(l)
#> [1] FALSE
all(b)
#> [1] FALSE
all(b, range=c(3, 3))
#> [1] TRUE
all.booltype(l, range=c(3, 3))
#> [1] TRUE
min(l)
#> [1] NA
min(b)
#> [1] 3
sum(l)
#> [1] NA
sum(b)
#> [1] 1
summary(l)
#> Mode FALSE TRUE NA's
#> logical 1 1 1
summary(b)
#> FALSE TRUE Min. Max.
#> 2 1 3 3
summary.booltype(l)
#> FALSE TRUE Min. Max.
#> 2 1 3 3