R/util_check_one_unique_value.R

Defines functions util_check_one_unique_value

Documented in util_check_one_unique_value

#' Check for one value only
#'
#' utility function to identify variables with one value only.
#'
#' @param x vector with values
#'
#' @return logical(1): TRUE, if -- except NA -- exactly only one value
#'                           is observed in `x`,
#'                     FALSE otherwise
#'
util_check_one_unique_value <- function(x) {
  howmany <- length(unique(x[!is.na(x)]))
  return(as.logical(ifelse(howmany == 1, 1, 0)))
}

Try the dataquieR package in your browser

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

dataquieR documentation built on July 26, 2023, 6:10 p.m.