Convenience function to get decreasing factor levels from cut
.
Currently requires specifying breaks
as vector of cutpoints rather
than number of desired intervals.
cut_decreasing(x, breaks, include.lowest = FALSE, right = TRUE, ...)
See cut
.
specifying number of intervals is not currently supported).
Arguments to pass to cut
.
Factor variable.
# NOT RUN {
# In mtcars dataset, create 3 mpg groups
table(cut(mtcars$mpg, breaks = c(-Inf, 15, 20, Inf)))
# Repeat with cut_decreasing to get factor levels ordered from high to low.
# To match cut here, need to specify right = FALSE
table(cut_decreasing(mtcars$mpg, breaks = c(Inf, 20, 15, -Inf), right = FALSE))
# You can specify breaks from low to high, but then include.lowest and right
# arguments get confusing
table(cut_decreasing(mtcars$mpg, breaks = c(-Inf, 15, 20, Inf), right = TRUE))
# }
Run the code above in your browser using DataLab