cut-number
Cut a numeric vector into n bins of (approximately) equal count.
Bin boundaries are quantiles of values using the type-7 linear interpolation rule, the same convention as src/utils/summaries.typ and src/stat/boxplot.typ. Bins are right-open ((lo, hi]), with the leftmost bin closed on the left.
Usage
cut-number(
values,
n: 4,
labels: auto,
)Parameters
| Parameter | Default | Description |
|---|---|---|
values |
Array of numbers; non-numeric or none entries map to none. |
|
n |
4 |
Number of bins. Must be positive. |
labels |
auto |
Either auto for default boundary labels, or an array of length n providing explicit labels. |
Returns
Array of bin labels with the same length as values.
Examples
Quartile bins so each bin holds roughly the same number of observations.
#let bins = cut-number((1, 2, 3, 4, 5, 6, 7, 8), n: 4)Tertile bins with custom labels.
#let bins = cut-number(
(1, 2, 3, 4, 5, 6, 7, 8, 9),
n: 3,
labels: ("low", "mid", "high"),
)