powered by
This is an enhanced version of base::cut() that allows a custom formatting to be applied to the values.
base::cut()
cut_format( x, breaks, include.lowest = FALSE, right = TRUE, ordered_result = FALSE, ..., format_fun = format, sep = ", ", paren = c("(", "[", ")", "]") )
a numeric vector which is to be converted to a factor by cutting.
[numeric] A vector of two or more unique cut points
[numeric]
logical, indicating if an ‘x[i]’ equal to the lowest (or highest, for right = FALSE) ‘breaks’ value should be included.
right = FALSE
logical, indicating if the intervals should be closed on the right (and open on the left) or vice versa.
logical: should the result be an ordered factor?
Passed to cut()
cut()
[function(x): character] A vectorized function that performs the desired formatting. Default: base::format()
[function(x): character]
base::format()
[character(1)] The separator between lower and upper end of the interval. Default: ", "
[character(1)]
", "
[character(4)] Opening and closing parentheses in two variants. Default: c("(", "[", ")", "]")
[character(4)]
c("(", "[", ")", "]")
https://stackoverflow.com/q/14456371/946850
cut_format(runif(10), seq(0, 1, by = 0.25), format_fun = function(x) paste(x * 100, "%")) cut_format(runif(10), seq(0, 1, by = 0.25), paren = c("<", "{", ">", "}"))
Run the code above in your browser using DataLab