You are able to apply filters in the Data Editor to highlight only certain cases in the data. This is most useful when you want to delete cases based on a filter, but can also help with sorting/filtering the data for manual editing as well. You can use R to create filters to help with this. Some common examples of when you may want to do this using R are below. These are all example code you can copy and modify within your R filter variable.
Requirements
- Understand how to use the Data Editor, see How to View or Edit Raw Data in Displayr.
- Have done the first Method in How to Use R Code to Create a Filter Based on Single-Response Questions to have an R filter variable with blank R CODE.
Please note these steps require a Displayr license.
Method - Based on a User Identifier Variable
#identify the respondent id you want to match your list of identifiers to
thevar = UID
#provide a list of ids to remove
#if your id variable is in a Numeric structure you should remove the double quotes below
theids = c("ab123","245ghs")
#create logic for the filter to flag the ids to delete
thevar %in% theids
Method - Based on Case Number
#choose a single variable to use to see how many cases are in the data set
refvar = Q1
#make a list of cases to delete based on their row number in the data set
thecases = c(1,2,3,4)
#create the filter initially with all 0s which excludes all respondents
thefilter = rep(0,length(refvar))
#change only the cases you want to delete to a 1 to be filtered in
thefilter[thecases] = 1
#return the final result
thefilter
Method - Duplicate Records
The code for this is discussed in more depth in How to Remove Duplicate Cases From a Data Set.
Method - Based on response(s)
Typically you can create a filter based on specific responses in our filtering tool, but sometimes you may need more complex logic or logic that's not supported.
#this example will flag users whose response in Q1 was more than Q2
Q1 > Q2
Though you can do the following without R CODE by creating a Calculation > Sum > SumEachRow variable and using that in the filtering tool, you can also do it in R CODE:
#this example will flag users whose responses in a variable set don't add up to 100
theset = `Your Variable Set Label Here in Backticks`
#perform the logic
SumEachRow(theset) != 100
More examples of creating filters in R can be found in How to Use R Code to Create a Filter Based on Single-Response Questions and logic statement examples in How to Work with Conditional R Formulas.
Additional Notes
- If appropriate to your scenario, you may want to look into the
seq()
function which can create a series of numbers automatically following a pattern. - If working with ids that follow a pattern/sequence, you may also look into How to Use Paste Functions to Create Dynamic Text Using R for how to use
paste()
to automatically create a list of ids following a pattern.