cut_quantile_bins | R Documentation |
This cuts a numeric vector into sample quantile bins.
cut_quantile_bins(
x,
probs = c(0.25, 0.5, 0.75),
labels = NULL,
type = 7,
ordered = TRUE
)
x |
( |
probs |
( |
labels |
( |
type |
( |
ordered |
( |
A factor
variable with appropriately-labeled bins as levels.
Intervals are closed on the right side. That is, the first bin is the interval
[-Inf, q1]
where q1
is the first quantile, the second bin is then (q1, q2]
, etc.,
and the last bin is (qn, +Inf]
where qn
is the last quantile.
# Default is to cut into quartile bins.
cut_quantile_bins(cars$speed)
# Use custom quantiles.
cut_quantile_bins(cars$speed, probs = c(0.1, 0.2, 0.6, 0.88))
# Use custom labels.
cut_quantile_bins(cars$speed, labels = paste0("Q", 1:4))
# NAs are preserved in result factor.
ozone_binned <- cut_quantile_bins(airquality$Ozone)
which(is.na(ozone_binned))
# So you might want to make these explicit.
explicit_na(ozone_binned)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.