R/factor_drop.R

Defines functions factor_drop

#' Drop empty factor levels
#'
#' @description
#' Avoids predict() issues. This is \code{forcats::fct_drop()}
#' without bells and whistles.
#'
#' @param f factor
#'
#' @return Factor
#' @noRd
factor_drop <- function(f) {
  factor_levels <- levels(f)
  factor(f, levels = setdiff(factor_levels, factor_levels[table(f) == 0]))
}

Try the batchtma package in your browser

Any scripts or data that you put into this service are public.

batchtma documentation built on Feb. 24, 2026, 1:06 a.m.