R/fix_blanks_with_na.R

Defines functions fix_blanks_with_na

Documented in fix_blanks_with_na

#' Replace blanks with NA in a data frame
#'
#' This function replaces all empty string values ("") in a given data frame with NA values.
#'
#' @param df A data frame to be processed.
#'
#' @return The data frame with empty string values replaced with NAs.
#'
#' @examples
#' df <- data.frame(x = c("", "foo", ""), y = c("", "", "bar"), z = c(1, 2, 3))
#' fix_blanks_with_na(df)
#'
#' @export
fix_blanks_with_na <- function(df) {
  df[df == ""] <- NA
  return(df)
}

Try the fixr package in your browser

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

fixr documentation built on April 4, 2025, 12:30 a.m.