Learn R Programming

sjmisc (version 1.0.0)

set_na: Set NA for specific variable values

Description

This function sets specific values of a variable var as missings (NA).

Usage

set_na(var, values)

Arguments

var
a variable where new missing values should be defined.
values
a numeric vector with values that should be replaced with NA's.

Value

  • The var where each value of values replaced by an NA.

See Also

rec for general recoding of variables and recode_to for re-shifting value ranges.

Examples

Run this code
# create random variable
dummy <- sample(1:8, 100, replace=TRUE)
# show value distribution
table(dummy)
# set value 1 and 8 as missings
dummy <- set_na(dummy, c(1,8))
# show value distribution, including missings
table(dummy, exclude=NULL)

Run the code above in your browser using DataLab