bin {MIfuns}R Documentation

Calculate Bin Sizes and Limits for a Vector (beta)

Description

Given a numeric vector, calculate bin limits, place each value in a bin, and return the number of values in each bin.

Usage

bin(x, population = x, breaks = quantile(population,
                                probs = c(0, 0.25, 0.5, 0.75, 1), ...), ...)

Arguments

x A vector of numeric values, to be placed in bins.
population A vector of numeric values serving as the reference population for constructing bins.
breaks Bin limits (boundaries) to pass to cut().
... Other arguments to pass to quantile(), table(), or cut().

Details

By default, the population used to calculate bin limits is the same as the group of values being binned. By default, inner bin limits are the quartiles of the population.

Value

A table with bin limits encoded as column names.

Author(s)

Tim Bergsma

See Also

quantile, table, cut

Examples

bin(1:100)
bin(1:50,population=1:100)
plot(
    bin(
        rnorm(1000), 
        breaks=seq(
                from=-3,
                to=3,
                by=0.5
        )
    )
)

[Package MIfuns version 3.2.9 Index]