recode_na_as: Replace missing values with another value

View source: R/recode_na_as.R

recode_na_asR Documentation

Replace missing values with another value

Description

This provides a convenient way to recode "NA" as another value for instance "NaN", "n/a" or any other value a user wishes to use.

Usage

recode_na_as(
  df,
  value = 0,
  subset_cols = NULL,
  pattern_type = NULL,
  pattern = NULL,
  case_sensitive = FALSE,
  ...
)

Arguments

df

A data.frame object for which recoding is to be done.

value

The value to convert to 'NA'. We can for instance change "n/a" to 'NA' or any other value.

subset_cols

An optional character vector to define columns for which changes are required.

pattern_type

One of contains', 'starts_with' or 'ends_with'.

pattern

A character pattern to match

case_sensitive

Defaults to FALSE. Patterns are case insensitive if TRUE

...

Other arguments to other functions

Value

An object of the same type as x with NAs replaced with the desired value.

Examples

head(recode_na_as(airquality, "n/a"))
head(recode_na_as(airquality, subset_cols = "Ozone", value = "N/A"))
head(recode_na_as(airquality, value=0, pattern_type="starts_with",
pattern="Solar"))

Nelson-Gon/mde documentation built on March 23, 2022, 10:58 p.m.