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
.
h_ws_to_na(x)
(vector
) where empty of white space should be transformed to NAs
.
character
or factor
without explicit NA. logical
and numeric
are returned as character
.
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