Helper to replace missing values. Default is to repalce NAs by 'mean' - 1 'sd'.
Usage
repl_na(x, replace_na = c("mean-sd", "min", 0, F))
Arguments
- x
A numerical vector.
- replace_na
Specifies the value used to replace NAs. Can take values:
'mean-sd' (charcter): replace NAs by mean - 1sd. Default.
'min' (charcter): replace NAs by minimum.
0 (numerical): replace NAs by 0.
FALSE (logical): do not replace NAs.
Examples
a <- c(rnorm(7), NA, NA, NA)
repl_na(a) == repl_na(a, 'mean-sd')
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
repl_na(a, 'min')
#> [1] 0.3295078 -0.8204684 0.4874291 0.7383247 0.5757814 -0.3053884
#> [7] 1.5117812 -0.8204684 -0.8204684 -0.8204684
repl_na(a, 0)
#> [1] 0.3295078 -0.8204684 0.4874291 0.7383247 0.5757814 -0.3053884
#> [7] 1.5117812 0.0000000 0.0000000 0.0000000
repl_na(a, FALSE)
#> [1] 0.3295078 -0.8204684 0.4874291 0.7383247 0.5757814 -0.3053884
#> [7] 1.5117812 NA NA NA