View source: R/identify_inconsistent.r
identify_inconsistent | R Documentation |
When conducting a panel study, we often want to know whether the same person has answered at all waves. One way of investigating this is to check whether people provided consistent birthdates or gender across several waves. This function allows to check the consistency in answers between up to three variables. It returns a vector with the consistent values. Participants with inconsistent answers receive the number -99
which can in turn be used to subset the overall data set.
identify_inconsistent(..., na.rm = FALSE)
... |
The variables that should be evaluated (up to three). |
na.rm |
Should people with missings in one of the variables be excluded (i.e., receive the value "-99")? If not (the default), the remaining variables will be checked for consistency. |
A vector in which participants with consistent answers receive the matching value and participants with inconsistent answers recevied a "-99".
# Create example data
(data <- data.frame(x1 = c(1,2,NA), x2 = c(1,2,3)))
# Create new variable with consistent answers
data$x <- identify_inconsistent(x1, x2, na.rm = T)
# Check
data
# Subset data based on function's output
subset(data, x != -99)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.