recode_as_na: Recode a value as NA

Description Usage Arguments Value Examples

View source: R/recode_as_na.R

Description

This provides a convenient way to convert a number/value that should indeed be an "NA" to "NA". In otherwords, it converts a value to R's recognized NA.

Usage

1
2
3
4
5
6
7
8
9
recode_as_na(
  df,
  value = NULL,
  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 class as x with values changed to 'NA'.

Examples

1
2
3
head(recode_as_na(airquality,value=c(67,118),pattern_type="starts_with",pattern="S|O"))
head(recode_as_na(airquality,value=c(41),pattern_type="ends_with",pattern="e"))
head(recode_as_na(airquality, value=41,subset_cols="Ozone"))

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

Related to recode_as_na in mde...