[Experimental]

SAS imports missing data as empty strings or white spaces. This helper function is a thin wrapper around h_ws_to_na which replaces them with explicit missing level.

h_ws_to_explicit_na(x, na_level = "<Missing>")

Arguments

x

(vector) where empty of white space should be transformed to NAs.

na_level

(character) replacement of the missing levels.

Value

factor with explicit NA

Examples

char1 <- c(" ", "    ", "a", "b", "", "")
h_ws_to_explicit_na(char1)
#> [1] <Missing> <Missing> a         b         <Missing> <Missing>
#> Levels: a b <Missing>

fact1 <- as.factor(char1)
h_ws_to_explicit_na(fact1)
#> [1] <Missing> <Missing> a         b         <Missing> <Missing>
#> Levels: a b <Missing>

num1 <- c(1, 2, NA)
h_ws_to_explicit_na(num1)
#> [1] 1         2         <Missing>
#> Levels: 1 2 <Missing>

logi1 <- c(TRUE, FALSE, NA)
h_ws_to_explicit_na(logi1)
#> [1] TRUE      FALSE     <Missing>
#> Levels: FALSE TRUE <Missing>