breaks: Generate Break Points for Equidistant or Quantile Bins

View source: R/breaks.R

breaksR Documentation

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)

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.

Value

A numeric vector containing the break points.

Examples

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

exams.forge documentation built on Aug. 21, 2025, 5:41 p.m.