Learn R Programming

DataCombine (version 0.2.21)

NaVar: Create new variable(s) indicating if there are missing values in other variable(s)

Description

Create new variable(s) indicating if there are missing values in other variable(s)

Usage

NaVar(data, Var, Stub = "Miss_", reverse = FALSE, message = TRUE)

Arguments

data
a data frame object.
Var
a character vector naming the variable(s) within which you would like to identify missing values.
Stub
a character string indicating the stub you would like to append to the new variables' name(s).
reverse
logical. If reverse = FALSE then missing values are coded as 1 and non-missing values are coded as 0. If reverse = TRUE then missing values are coded as 0 and non-missing values are coded as 1.
message
logical. Whether or not to give you a message about the names of the new variables that are created.

Examples

Run this code
# Create data frame
a <- c(1, 2, 3, 4, NA)
b <- c( 1, NA, 3, 4, 5)
ABData <- data.frame(a, b)

# Create varibles indicating missing values in columns a and b
ABData1 <- NaVar(ABData, Var = c('a', 'b'))

# Create varible indicating missing values in columns a with reversed dummy
ABData2 <- NaVar(ABData, Var = 'a', reverse = TRUE, message = FALSE)

Run the code above in your browser using DataLab