njtierney / naniar

Tidy data structures, summaries, and visualisations for missing data
http://naniar.njtierney.com/
Other
652 stars 53 forks source link

Implement recode_shadow, which allows for special missing values #202

Closed njtierney closed 6 years ago

njtierney commented 6 years ago

Description

This change implements a flexible way to specify new, special missing values, as described in #50 and related issues.

Related Issue

Fixes #50

Example

library(naniar)

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

dfs <- bind_shadow(df)

dfs
#> # A tibble: 3 x 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 x 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 x 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

Created on 2018-08-20 by the reprex package (v0.2.0).

Tests

Yes, many tests have been added

NEWS + DESCRIPTION

NEWS and Description have been updated