View source: R/vector_operations.R
discretize | R Documentation |
A wrapper for base-r's cut() with some improved features.
discretize(
x,
breaks,
equal_range = T,
labels = "interval",
include_end = T,
right = T,
ordered_factor = F,
...
)
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(). |
x = discretize(rnorm(100), 5)
hist(x)
y = discretize(rnorm(100), 5, equal_range = F)
hist(y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.