| maxindex.default {bit} | R Documentation |
Get maxindex (length of boolean vector) and poslength (number of 'selected' elements)
Description
For is.booltype() objects the term length() is ambiguous.
For example the length of which() corresponds to the sum of logical().
The generic maxindex gives length(logical) for all booltype()s.
The generic poslength gives the number of positively selected elements, i.e.
sum(logical) for all booltype()s (and gives NA if NAs are present).
Usage
## Default S3 method:
maxindex(x, ...)
## Default S3 method:
poslength(x, ...)
## S3 method for class 'logical'
maxindex(x, ...)
## S3 method for class 'logical'
poslength(x, ...)
## S3 method for class 'bit'
maxindex(x, ...)
## S3 method for class 'bit'
poslength(x, ...)
## S3 method for class 'bitwhich'
maxindex(x, ...)
## S3 method for class 'bitwhich'
poslength(x, ...)
## S3 method for class 'which'
maxindex(x, ...)
## S3 method for class 'which'
poslength(x, ...)
## S3 method for class 'ri'
maxindex(x, ...)
## S3 method for class 'ri'
poslength(x, ...)
maxindex(x, ...)
poslength(x, ...)
Arguments
x |
an R object, typically a |
... |
further arguments (ignored) |
Value
an integer scalar
Methods (by class)
-
maxindex(default): default method formaxindex -
maxindex(logical):maxindexmethod for classlogical() -
maxindex(bit):maxindexmethod for classbit() -
maxindex(bitwhich):maxindexmethod for classbitwhich() -
maxindex(which):maxindexmethod for classwhich() -
maxindex(ri):maxindexmethod for classri()
Functions
-
poslength(default): default method forposlength -
poslength(logical):poslengthmethod for classlogical() -
poslength(bit):poslengthmethod for classbit() -
poslength(bitwhich):poslengthmethod for classbitwhich() -
poslength(which):poslengthmethod for classwhich() -
poslength(ri):poslengthmethod for classri()
Examples
r <- ri(1, 2, 12)
i <- as.which(r)
w <- as.bitwhich(r)
b <- as.bit(r)
l <- as.logical(r)
u <- which(l) # unclassed which
sapply(list(r=r, u=u, i=i, w=w, b=b, l=l), function(x) {
c(length=length(x), sum=sum(x), maxindex=maxindex(x), poslength=poslength(x))
})