Learn R Programming

tern (version 0.9.10)

explicit_na: Missing data

Description

[Stable]

Substitute missing data with a string or factor level.

Usage

explicit_na(x, label = default_na_str(), drop_na = default_drop_na())

default_drop_na()

set_default_drop_na(drop_na)

Value

x with any NA values substituted by label.

  • tern_default_drop_na: (flag)
    default value for drop_na argument in explicit_na().

  • tern_default_drop_na has no return value.

Arguments

x

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

label

(string)
string that missing data should be replaced with.

drop_na

(flag)
if TRUE and x is a factor, any levels that are only label will be dropped.

Functions

  • default_drop_na(): should NA values without a dedicated level be dropped?

  • set_default_drop_na(): Setter for default NA value replacement string. Sets the option "tern_default_drop_na" within the R environment.

Examples

Run this code
explicit_na(c(NA, "a", "b"))
is.na(explicit_na(c(NA, "a", "b")))

explicit_na(factor(c(NA, "a", "b")))
is.na(explicit_na(factor(c(NA, "a", "b"))))

explicit_na(sas_na(c("a", "")))

explicit_na(factor(levels = c(NA, "a")))
explicit_na(factor(levels = c(NA, "a")), drop_na = TRUE) # previous default

Run the code above in your browser using DataLab