In order to combine variable sets into a -Grid Structure, Displayr needs to be able to identify how the variables match up into rows and columns between the Variable Sets. This article describes the requirements for joining together variables to make a -Grid Structure, and walks you through how to can use a QScript to combine several Binary-Multi variable sets into a Binary-Grid set, or several Number-Multi questions into a Number-Grid.
In this article, we will work through an example to produce a table that looks like this:
Requirements
The key things to keep in mind with grouping together variable sets into a grid structure are:
- Each variable needs to be stored in a Numeric - Multi or Binary - Multi variable set.
- Completeness - There must be a variable for every row and column combination of the grid. So each -Multi variable set should represent an individual row/column, and each -Multi set must contain a variable for every column/row that will be in the final grid. If a variable is missing, you can make a dummy variable of missing data to use as a placeholder with the correct label, see How to Create a Custom Numeric JavaScript Variable and use NaN as the value.
- Consistent Order – the order in which options appear for each attribute. You can drag and drop variables in the Data Sources tree to line them up correctly.
-
Consistent Labels – the labels of the questions must include both the final row and column names (Note: these are also case-sensitive). I’ve found it yields the best results to separate them using spaces and a special character like “–” or “:”. Displayr makes it easy to edit labels by changing them directly in the Data Sources tree individually, you can also copy and paste labels in bulk in the tree, or use Find/Replace to trim bits of the labels based on a pattern.
Method
Load the data
If you want to work through the example with the same data used in this article:
- Download the CSV file to your computer. The file we will be using in this example is called Cola_dataset.csv. You can use this link to download the file: CSV file.
- Create a new Displayr document and load the data. See Get Your Data Into Displayr for more information.
Review the data
You can see the brand attitude question looking at attitudes and colas is broken into several questions and in different formats. For example, the feminine questions are already stored in a grid, but in contrast, the health-conscious questions are broken into multiple variables.
The rest of the questions we want to use (innocent, older, open to new experiences, rebellious, sleepy, and traditional) are stored in another variable called Grid...
This article will work through the tasks we need to accomplish to combine these variables into a single grid which we will call Brand Attitudes.
Standardize the labels
In order to combine the questions into the same grid, the variables in each variable set must have identical labels and be in the same order. We will edit the labels for health-conscious, innocent, older, open to new experiences, rebellious, sleepy, and traditional to match the ones for the feminine variables:
We will start with the health-conscious variables.
- In the Data Sources tree, right-click and Rename each label for the health-conscious variables to look like the feminine variable labels. For example, "Coke", "Diet Coke", etc. Ensure that there are no leading or trailing spaces on each label.
- After you have renamed all the labels, make sure that they are in the same order as the ones for feminine. If not, drag and drop the rows to make sure the options are in the same order.
- Highlight the health-conscious variables, right-click, and select Combine. You may need to right-click and select Rename to rename to "health-conscious".
The next step is to deal with the variables contained in the Grid variable.
- In the Data Sources, right-click on Grid and select Split.
- Rename the labels for the innocent rows to match the ones in the feminine rows (e.g., Coke, Diet Coke, etc.)
- Highlight the innocent rows, right-click the highlighted area, and select Combine.
The results are as follows:
- Repeat steps 1 and 2 for older, open to new experiences, rebellious, sleepy, and traditional.
Standardize the structure of each variable set
In order to combine the variable sets into the same grid, they must have one of the following structures: Numeric - Multi or Binary - Multi.
- In the Data Sources, select the variable sets you plan to combine into a grid.
- In the object Inspector, change the Data > Properties > Structure to Binary - Multi: Non-mutually exclusive categories.
- Click Fix if you get a message that the values to be counted should be verified and then OK.
Create the Final Grid
To combine the variables into a grid:
- Select the variable sets feminine, health-conscious, innocent, older, open to new experiences, rebellious, sleepy, and traditional in the Data Sources tree.
- Right-click and select Combine > As Grid.
- Rename your new grid to "Brand Attitudes".
You now have a grid variable named Brand Attitudes.