Learn R Programming

oce (version 1.8-1)

binCount1D: Bin-count vector data

Description

Count the number of elements of a given vector that fall within successive pairs of values within a second vector.

Usage

binCount1D(x, xbreaks, include.lowest = FALSE)

Value

A list with the following elements: the breaks (xbreaks, midpoints (xmids) between those breaks, and the count (number) of x values between successive breaks.

Arguments

x

vector of numerical values.

xbreaks

Vector of values of x at the boundaries between bins, calculated using pretty() if not supplied.

include.lowest

logical value indicating whether to include x values that equal xbreaks[1]. See “Details”.

Author

Dan Kelley

Details

By default, the sub-intervals defined by the xbreaks argument are open on the left and closed on the right, to match the behaviour of cut(). An open interval does not include points on the boundary, and so any x values that exactly match the first breaks value will not be counted. To count such points, set include.lowest to TRUE.

To contextualize binCount1D() in terms of base R functions, note that

binCount1D(1:20, seq(0, 20, 2))$number

matches

unname(table(cut(1:20, seq(0, 20, 2))))

See Also

Other bin-related functions: binApply1D(), binApply2D(), binAverage(), binCount2D(), binMean1D(), binMean2D()