discretize: Discretize a variable

View source: R/vector_operations.R

discretizeR Documentation

Discretize a variable

Description

A wrapper for base-r's cut() with some improved features.

Usage

discretize(
  x,
  breaks,
  equal_range = T,
  labels = "interval",
  include_end = T,
  right = T,
  ordered_factor = F,
  ...
)

Arguments

x

(numeric vector) A vector of datapoints to discretize.

breaks

(integer scalar or numeric vector) The number of levels to create, or a numeric vector of values to use as cut-offs.

equal_range

(logical scalar) Whether to use equal ranges. If false, will use equal sizes. Defaults to TRUE.

labels

(character scalar) Which labels to use. By default, it will use the intervals. Can also be "midpoint", which uses the interval midpoints, "numbers" will use integers.

include_end

(logical scalar) Whether to include datapoints equal to the last break value. Default=TRUE.

right

(logical scalar) Whether to use intervals that are closed on the right. Default=TRUE.

ordered_factor

(logical scalar) Should the result be an ordered factor? Default=FALSE.

...

(additional arguments) Any other arguments passed to cut().

Examples

x = discretize(rnorm(100), 5)
hist(x)
y = discretize(rnorm(100), 5, equal_range = F)
hist(y)

Deleetdk/kirkegaard documentation built on April 22, 2024, 5:22 p.m.