Introduction
This article describes how to go from a raw data table...
...to a table that shows only the unique responses:
Requirements
A raw data table with multiple columns created via custom code in an R Output or Create > Tables > Raw Data > Variables. See How to Export Raw Data to Excel for details on creating the latter. In this example, our table is called cola.raw.data. To perform this on your Data Set see How to Remove Duplicate Cases From a Data Set.
Method
1. Select Calculation > Custom Code.
2. Update the Name on the object inspector under Properties > GENERAL.
3. Paste the below under Properties > R CODE:
df = unique(cola.raw.data)
Note, when there are multiple columns of data, the unique function will look at the unique combination of all columns.
To instead filter the table on unique categories from the first column, you would use:
df = unique(cola.raw.data[,1])
4. An alternative is to use the duplicated function which offers more flexibility. The below is the equivalent of the previous code:
x = cola.raw.data
df = x[!duplicated(x[,1]),]
By default, in both situations, the code de-duplicates by displaying the first unique row when there are duplicates. However, by appending the fromLast argument, we can display the last row instead:
df = x[!duplicated(x[,1], fromLast=T),]
Note, that using the below code only will result in a TRUE or FALSE based on whether the condition is met.
!duplicated(x[,1])
Next
How to Work with Conditional R Formulas