Learn R Programming

sjmisc (version 1.2)

replace_na: Replace NA with specific values

Description

This function replaces NA's of a variable, data frame or list of variables with value.

Usage

replace_na(x, value)

Arguments

x
Variable (vector), data.frame or list of variables where missing values should be replaced with value.
value
Value that will replace the NA's.

Value

  • x, where NA's are replaced with value.

See Also

set_na for setting NA values, rec for general recoding of variables and recode_to for re-shifting value ranges.

Examples

Run this code
data(efc)
table(efc$e42dep, exclude = NULL)
table(replace_na(efc$e42dep, 99), exclude = NULL)

dummy <- list(efc$c82cop1, efc$c83cop2, efc$c84cop3)
# show original distribution
lapply(dummy, table, exclude = NULL)
# show variables, NA's replaced with 99
lapply(replace_na(dummy, 99), table, exclude = NULL)

Run the code above in your browser using DataLab