cut-width
Cut a numeric vector into bins of fixed width.
Bins span width units; when center is provided, bin boundaries are shifted so that center lies at a bin centre. Otherwise boundaries align to multiples of width covering [min, max]. Bins are right-open ((lo, hi]), except the leftmost bin is closed on the left.
Usage
cut-width(
values,
width: 1,
center: none,
labels: auto,
)Parameters
| Parameter | Default | Description |
|---|---|---|
values |
Array of numbers; non-numeric or none entries map to none. |
|
width |
1 |
Positive bin width. |
center |
none |
Optional number forcing a bin to be centred at this value. |
labels |
auto |
Either auto for default boundary labels, or an array of length matching the number of bins. |
Returns
Array of bin labels with the same length as values.
Examples
Bin widths of 2 align to multiples of two.
#let bins = cut-width((1, 2, 3, 4, 5, 6, 7, 8), width: 2)Force a bin to be centred at zero by passing center.
#let bins = cut-width((-3, -1, 0, 1, 2, 4), width: 2, center: 0)