Learn R Programming

tern (version 0.9.8)

sas_na: Convert strings to NA

Description

[Stable]

SAS imports missing data as empty strings or strings with whitespaces only. This helper function can be used to convert these values to NAs.

Usage

sas_na(x, empty = TRUE, whitespaces = TRUE)

Value

x with "" and/or whitespace-only values substituted by NA, depending on the values of empty and whitespaces.

Arguments

x

(factor or character)
values for which any missing values should be substituted.

empty

(flag)
if TRUE, empty strings get replaced by NA.

whitespaces

(flag)
if TRUE, strings made from only whitespaces get replaced with NA.

Examples

Run this code
sas_na(c("1", "", " ", "   ", "b"))
sas_na(factor(c("", " ", "b")))

is.na(sas_na(c("1", "", " ", "   ", "b")))

Run the code above in your browser using DataLab