Learn R Programming

exams.forge (version 1.0.11)

breaks: Generate Break Points for Equidistant or Quantile Bins

Description

Creates a numeric vector of break points for the given data x. The resulting breaks define bins that are either equidistant (fixed width) or non-equidistant (quantile-based). If width is not specified, it defaults to diff(pretty(x))[1]. The probs argument can either be a single integer, specifying the number of quantiles, or a numeric vector of probabilities in the interval \([0, 1]\).

Usage

breaks(x, width = NULL, probs = NULL)

add_breaks(x, width = NULL, probs = NULL)

dbreaks(x, width = NULL, probs = NULL)

Value

A numeric vector containing the break points.

Arguments

x

numeric vector: the data to compute breaks for.

width

numeric, optional: desired bin width (default: NULL, auto-calculated).

probs

numeric, optional: number of quantiles (single integer) or vector of probabilities in \([0, 1]\) for non-equidistant bins (default: NULL).

Details

If probs is used, break points are rounded to the nearest multiple of width. Duplicates are removed, and the range is extended if necessary to include the full range of x.

Examples

Run this code
x <- rnorm(100, mean = 1.8, sd = 0.1)
breaks(x)                # equidistant bins
breaks(x, width = 0.1)   # custom width bins
breaks(x, width = 0.1, probs = 4)  # quantile-based bins

Run the code above in your browser using DataLab