This article describes how the
QFilter object can be used within your R code to apply filters to respondent-level data.
- A Calculation that will return the same length as the number of non-deleted cases in your data set.
- One or more filter variables from the same data set.
1. In the toolbar, go to Calculation > Custom Code. In this example, we will just enter
Age so that it returns the age group of each individual record in our data set. There are 800 records in total.
2. Under Inputs > FILTERS & WEIGHT > Filter(s), apply the desired filter variable(s). If you apply multiple filters, a single variable is effectively created using an AND operation. Here, we will apply a Female filter:
QFilter in the rows parameter of your R code:
As this is a single variable, we simply need to place
QFilter within square brackets. If your output includes columns then it would be
Our Calculation now returns 405 records, the same number as females in our data set.
Note the following:
QFilterautomatically updates when the filters change.
- If no filters are applied, it takes a value of
- If you apply filters to your Calculation via Inputs > FILTERS & WEIGHT > Filter(s) but do not include
QFilterin your code, you will receive the following warning:
- The Variable Label is available as an attribute (i.e.,
attr(QFilter, "label")). Where there are multiple filters, they are concatenated as a list (e.g., "Male, 18 to 24 and Tall").
- The Variable Name is available as an attribute (i.e.,
attr(QFilter, "name")). Where there are multiple names, they are concatenated as with labels.