Transforming Empty Strings and White Spaces to NAs
h_ws_to_na.Rd
SAS imports missing data as empty strings or white spaces. This helper function replaces the empty strings and white
space-only character and levels by NAs
.
Examples
char1 <- c(" ", " ", "a", "b", "", "")
h_ws_to_na(char1)
#> [1] NA NA "a" "b" NA NA
fact1 <- as.factor(char1)
h_ws_to_na(fact1)
#> [1] <NA> <NA> a b <NA> <NA>
#> Levels: a b
num1 <- c(1:10)
h_ws_to_na(num1)
#> [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10"
logi1 <- c(TRUE, FALSE, NA)
h_ws_to_na(logi1)
#> [1] "TRUE" "FALSE" NA