R/cut_vector.R

#' @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/creditr documentation built on May 18, 2019, 8:12 p.m.