Skip to contents

It can be useful to add special missing values, naniar supports this with the recode_shadow function.

Usage

recode_shadow(data, ...)

# S3 method for data.frame
recode_shadow(data, ...)

# S3 method for grouped_df
recode_shadow(data, ...)

Arguments

data

data.frame

...

A sequence of two-sided formulas as in dplyr::case_when, but when a wrapper function .where written around it.

Value

a dataframe with altered shadows

Examples


df <- tibble::tribble(
~wind, ~temp,
-99,    45,
68,    NA,
72,    25
)

dfs <- bind_shadow(df)

dfs
#> # A tibble: 3 × 4
#>    wind  temp wind_NA temp_NA
#>   <dbl> <dbl> <fct>   <fct>  
#> 1   -99    45 !NA     !NA    
#> 2    68    NA !NA     NA     
#> 3    72    25 !NA     !NA    

recode_shadow(dfs, temp = .where(wind == -99 ~ "bananas"))
#> # A tibble: 3 × 4
#>    wind  temp wind_NA temp_NA   
#>   <dbl> <dbl> <fct>   <fct>     
#> 1   -99    45 !NA     NA_bananas
#> 2    68    NA !NA     NA        
#> 3    72    25 !NA     !NA       

recode_shadow(dfs,
              temp = .where(wind == -99 ~ "bananas")) %>%
recode_shadow(wind = .where(wind == -99 ~ "apples"))
#> # A tibble: 3 × 4
#>    wind  temp wind_NA   temp_NA   
#>   <dbl> <dbl> <fct>     <fct>     
#> 1   -99    45 NA_apples NA_bananas
#> 2    68    NA !NA       NA        
#> 3    72    25 !NA       !NA