R/cut_vector.R

Defines functions cut_vector

#' @importFrom stringr str_replace
#' @export
cut_vector <- function(x, breaks, closed_on_right = TRUE){
  breaks <- unique(c(-Inf, breaks, Inf))
  x_cut <- cut(x, breaks, right = closed_on_right)
  cut_levels <- levels(x_cut) %>% str_replace("(-| )Inf", "")

  x_cut %>%
    str_replace("(-| )Inf", "") %>%
    factor(levels = cut_levels)
}
louis-vines/miv.select documentation built on May 5, 2019, 9:19 a.m.