recode_na_as: Replace missing values with another value

Description Usage Arguments Value Examples

View source: R/recode_na_as.R

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

1
2
3
4
5
6
7
8
9
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

1
2
3
4
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"))

mde documentation built on Feb. 10, 2022, 5:08 p.m.

Related to recode_na_as in mde...