discretize_numbers: Discretize continuous numbers

discretize_numbersR Documentation

Discretize continuous numbers

Description

Discretize continuous numbers

Usage

discretize_numbers(x, min_size = 1, ...)

Arguments

x

vector of numbers.

min_size

minimum size of bins at the edges. Any bins smaller than this size are combined.

...

Arguments passed on to get_breaks

N

step size. The eventual intervals will be multiples of the divisors of N or multiples of N when multiples_only is TRUE. Defaults to 10.

max_breaks

maximum amount of breaks, defaults to 10.

int_only

whether only integer divisors of N may be used as breaks, defaults to TRUE.

multiples_only

whether only multiples of N can be used as breaks, defaults to FALSE.

Details

The function get_breaks is called to create the boundaries between groups. It is called on default with limits = range(x) and with include_bounds = FALSE. This behaviour may be overridden with the ... argument, although it is advised not to do so to avoid empty groups.

NA values are preserved in the result.

Value

A factor with the same length as x, with labels indicating bins.

Examples

ages = round(rnorm(1000,50,10)); ages[1] = NA
discretize_numbers(ages)

hgutils documentation built on March 31, 2022, 5:06 p.m.