Replace missing values with NA
Usage
replace_missing_values(
  data,
  target_columns = NULL,
  na_strings = cleanepi::common_na_strings
)Arguments
- data
 The input
<data.frame>or<linelist>- target_columns
 A
<vector>of column names. If provided, missing values will be substituted only in the specified columns. When the input data is a<linelist>object, this parameter can be set tolinelist_tagsto replace missing values withNAin the tagged columns only.- na_strings
 A
<vector>of characters that represent the missing values in the columns of interest. By default, it utilizescleanepi::common_na_strings. However, if the missing values string in the columns of interest is not included in this predefined vector, it can be used as the value for this argument. Matching ofdatawithna_stringsis insensitive to case and leading/trailing whitespace.
Examples
data <- readRDS(
  system.file("extdata", "test_df.RDS", package = "cleanepi")
)
# replace all occurrences of '-99' with NA
cleaned_data <- replace_missing_values(
  data = data,
  target_columns = NULL,
  na_strings = "-99"
)
# print the names of the columns where the replacement occurred
print_report(cleaned_data, "missing_values_replaced_at")
#> [1] "dateOfBirth" "sex"