Recode Missing Values Dictionary-Style

dict_recode(
  df,
  use_func = "recode_na_as",
  pattern_type = "starts_with",
  patterns,
  values
)

Arguments

df

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

use_func

Function to use for the recoding. One of the various `recode_*` functions in package `mde`.

pattern_type

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

patterns

A vector containing patterns to use for pattern_type

values

A vector containing values to match to the patterns vector

Value

A `data.frame` object with replacements as required.

Examples

head(dict_recode(airquality, pattern_type="starts_with",
patterns = c("Solar", "Ozone"), values = c(190, 41),
use_func="recode_as_na"))
#>   Ozone Solar.R Wind Temp Month Day
#> 1    NA      NA  7.4   67     5   1
#> 2    36     118  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
 head(dict_recode(airquality, pattern_type="starts_with",
patterns = c("Solar", "Ozone"), values = c(42, 420),
use_func="recode_na_as"))
#>   Ozone Solar.R Wind Temp Month Day
#> 1    41     190  7.4   67     5   1
#> 2    36     118  8.0   72     5   2
#> 3    12     149 12.6   74     5   3
#> 4    18     313 11.5   62     5   4
#> 5   420      42 14.3   56     5   5
#> 6    28      42 14.9   66     5   6