binCount1D: Bin-count Vector Data

View source: R/bin.R

binCount1DR Documentation

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)

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”.

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))))

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.

Author(s)

Dan Kelley

See Also

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


oce documentation built on Sept. 11, 2024, 7:09 p.m.