reverse_cut {dvmisc} | R Documentation |
Convenience function to get reversed factor levels from cut
.
Currently requires specifying breaks
as vector of cutpoints rather
than number of desired intervals.
reverse_cut(x, breaks, include.lowest = FALSE, right = TRUE, ...)
x , breaks , include.lowest , right |
See |
... |
Arguments to pass to |
Factor variable.
# In mtcars dataset, create 3 mpg groups
table(cut(mtcars$mpg, breaks = c(-Inf, 15, 20, Inf)))
# Repeat with reverse_cut to get factor levels ordered from high to low
table(reverse_cut(mtcars$mpg, breaks = c(Inf, 20, 15, -Inf)))
# You can specify breaks from low to high, but then include.lowest and right
# arguments get confusing
table(reverse_cut(mtcars$mpg, breaks = c(-Inf, 15, 20, Inf), right = TRUE))