Filters in R
Jump to navigation
Jump to search
R Outputs
An R Output can refer to a variable called QFilter. Key properties of QFilter are:
- It automatically updates when the filters change.
- If no filters are applied, it takes a value of TRUE.
- If a filter is applied, it has the same length as the number of non-deleted cases in the Data Set.
- Where multiple filters are applied, a single variable is created (using an and operation).
- The Variable Label is available as an attribute (i.e., attr(QFilter, "label")). Where there are multiple filters, they are concatenate as a list (e.g., "Male, 18 to 24 and Tall").
- The Variable Name is available as an attribute (i.e., attr(QFilter, "label")). Where there are multiple names, they are concatenates as with labels.
Approaches to using filters when writing R code
R code typically needs to do the following things when taking filters into account:
- Filter the data. The data may either by passed in to a function in some format, or, extracted indirectly from the environment.
- Clean the data in the filter.
- The name or label of the filter in the output.
The most straightforward way to deal with these is to use an existing analysis as a template (e.g., flipMultivariates::LDA). Base R has a standard function for filtering data called subset.