R/zap_empty.R

Defines functions zap_empty

Documented in zap_empty

#' Convert empty strings into missing values
#'
#' @param x A character vector
#' @return A character vector with empty strings replaced by missing values.
#' @family zappers
#' @export
#' @examples
#' x <- c("a", "", "c")
#' zap_empty(x)
zap_empty <- function(x) {
  stopifnot(is.character(x))

  x[x == ""] <- NA
  x
}

Try the haven package in your browser

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

haven documentation built on July 10, 2023, 2:04 a.m.