This provides a convenient way to convert a number/value to another value.

recode_as_value(
  df,
  value = NULL,
  replacement_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/vector of values to convert.

replacement_value

New 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

head(recode_as_value(airquality,
value=c(67,118),replacement=NA, pattern_type="starts_with",pattern="S|O"))
#>   Ozone Solar.R Wind Temp Month Day
#> 1    41     190  7.4   67     5   1
#> 2    36      NA  8.0   72     5   2
#> 3    12     149 12.6   74     5   3
#> 4    18     313 11.5   62     5   4
#> 5    NA      NA 14.3   56     5   5
#> 6    28      NA 14.9   66     5   6