This article describes how to combine the code within two or more R filter variables that are connected to control boxes into a single filter variable.
- One or more control boxes (created via Anything > Page Design > Control).
- One or more R filter variables that reference these control boxes.
In short, this is as easy as copying the original code from both variables and combining them with the & (AND) symbol.
1. Select each variable in the Data Sets tree that you wish to combine and copy the code under Properties > R CODE:
Age %in% combo.box.age
Gender %in% combo.box.gender
2. We can now combine our Age control filter with our Gender control filter by separating them with an &:
Age %in% combo.box.age & Gender %in% combo.box.gender
Here, the logic is looking at whether the selection in combo.box.age matches the category in the Age variable AND the selection in combo.box.gender matches the category in the Gender variable.
3. We can also combine multiple and single-response conditions, such as Brand Awareness and Income:
rowSums(`Brand Awareness`[, combo.box.brand, drop = FALSE]) > 0 & Income %in% combo.box.income
Here, the logic is looking at whether the selection in combo.box.brand has been selected in the Brand Awareness variable set AND the selection in combo.box.income matches the category in the Income variable.
In both cases, the final result must be a TRUE/FALSE or 1/0. By using the & operator, the result will only return TRUE if both conditions are TRUE.