Count the number of elements of a given vector that fall within successive pairs of values within a second vector.
binCount1D(x, xbreaks, include.lowest = FALSE)
A list with the following elements: the breaks (xbreaks
,
midpoints (xmids
) between those breaks, and
the count (number
) of x
values between successive breaks.
vector of numerical values.
Vector of values of x at the boundaries between bins, calculated using
pretty()
if not supplied.
logical value indicating whether to include
x
values that equal xbreaks[1]
. See “Details”.
Dan Kelley
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))))
Other bin-related functions:
binApply1D()
,
binApply2D()
,
binAverage()
,
binCount2D()
,
binMean1D()
,
binMean2D()