Many times you will want to only include respondents in analyses that have a completed survey, or more specifically have answered all of a set of questions. This article describes how to create a filter variable that only includes cases with complete data (ie, no missing values) across selected variables. The raw data table below shows an example of how the Complete filter variable (in the last column) is calculated based on the variables selected in the columns to the right of it:
A Displayr Document with a Data Set.
Method - Automatic
- In the Data Sets tree, select the select specific variable sets that you would like to use in the filter.
- Go to Anything > Data > Missing Data > Save Variable(s) > Filter for Complete Cases.
- Click OK.
- A new filter variable will appear in the Data Sets tree that you can apply to your outputs and analyses.
Method - Using R
- Create an R variable, see How to Create a Custom Numeric R Variable.
- In the object inspector, ensure Usable as a filter is checked.
- Paste in and modify the following code in the object inspector > R CODE box:
#make a table of all of the variables to identify complete cases
#replace the variable set names within data.frame() with a comma separated
#list of your own, you can click on the variable set in the Data Sets tree
#to insert it into the code
mytab = data.frame(Age,`D2 - Income`,Gender,`Q3 - Preferred cola`)
#calculate complete cases across each row in the table