Learn R Programming

matrixStats (version 0.8.5)

binCounts: Fast element counting in non-overlapping bins

Description

Counts the number of elements in non-overlapping bins

Usage

## S3 method for class 'default':
binCounts(x, bx, ...)

Arguments

x
A numeric vector of K positions for to be binned and counted.
bx
A numeric vector of B+1 ordered positions specifying the B bins [bx[1],bx[2]), [bx[2],bx[3]), ..., [bx[B],bx
...
Not used.

Value

  • Returns an integer vector of length B with non-negative integers.

Missing and non-finite values

Missing values in x are ignored/dropped. Missing values in bx are not allowed and gives an error.

See Also

Note that hist is almost as fast for counting occurances within bins, e.g. hist(x, breaks=bx, right=FALSE, plot=FALSE)$counts.

To average values within bins, see binMeans().