If your Calculation uses variables or a raw data table as an input (as opposed to a table/visualization/other output), you can use the standard Filter(s) dropdowns to quickly filter your R Output. This article describes how the
QFilter object can be used within your R code to apply filters to respondent-level data.
- A Calculation that uses variables from the data set or an unfiltered raw data table.
- 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.
How to Add a Custom Calculation
How to Work with R in Displayr
How to Filter Raw Data Using R
How to Use Different Types of Data in R
Article is closed for comments.