R/should_factor_stay_factor.R

#' Should this really be a factor?
#'
#' @param x factor
#'
#' @return boolean; \code{TRUE} if the number of unique values does not equal to the length, and \code{FALSE} otherwise.
#' @export
#' @examples
#' abb <- factor(c("a", "b", "b"))
#' abc <- factor(c("a", "b", "c"))
#'
#' # This should be a factor:
#' should_factor_stay_factor(abb)
#'
#' # This should not be a factor
#' should_factor_stay_factor(abc)
should_factor_stay_factor <- function(x){
  if (is.factor(x))
    length(x) != length(unique(x))
  else
    stop("please specify a factor")
}
csiu/foofactor documentation built on May 14, 2019, 12:24 p.m.