reverse_cut: Reverse Cut

Description Usage Arguments Value Examples

View source: R/reverse_cut.R

Description

Convenience function to get reversed factor levels from cut. Currently requires specifying breaks as vector of cutpoints rather than number of desired intervals.

Usage

1
reverse_cut(x, breaks, include.lowest = FALSE, right = TRUE, ...)

Arguments

x, breaks, include.lowest, right

See cut. specifying number of intervals is not currently supported).

...

Arguments to pass to cut.

Value

Factor variable.

Examples

1
2
3
4
5
6
7
8
9
# 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))

dvmisc documentation built on Dec. 18, 2019, 1:35 a.m.