This article describes how to go from a raw data table...
...to a filtered table based on a defined condition:
A raw data table with multiple columns created via custom code or Create > Tables> Raw Data > Variables. In this example, our table is called cola.raw.data.
1. Select Create > R Ouput.
2. Update the Name on the object inspector under Properties > GENERAL.
3. Paste the below under Properties > R CODE:
df = cola.raw.data
new.df = df[df[,2] %in% c("Coca-Cola"),]
- In this example, we wish to filter our table by those who chose Coca-Cola as their preferred cola.
- Above, we filter our df table by rows where the data matches Coca-Cola in the second column using the %in% operator.
- Note, you can also add further items to the filter condition as follows:
Alternatively, you can first define your filter condition using one of the below methods:
f = df[,2] %in% c("Coca-Cola")
f = df[,2] == "Coca-Cola"
Note, that using the above code only will result in a TRUE or FALSE based on whether the condition is met.
The last line can then be amended as follows, to filter the rows based on the true or false result stored in f.
new.df = df[f,]