This article describes how to go from a table with averages on the right...
...to a table that includes the averages in the row labels:
Requirements
A Nominal - Multi table with statistics to the right.
Please note these steps require a Displayr license.
Method
1. Select your table.
2. Go to Data > RULES on the object inspector.
3. Click the Plus (+) button.
4. Click New custom rule (write your own JavaScript) > Edit JavaScript.
5. Paste the below into the dialog:
form.setHeading("Add table statistic to labels");
form.setSummary("Add table statistic to labels");
includeWeb('Table JavaScript Utility Functions');
// Set parameters and text
var statistic_to_add = "Average";
var decimals = 2;
var text_before = "Average =";
// Get labels and values
var vals = right_table.get(statistic_to_add);
var row_labs = table.rowLabels;
var new_labs = [];
// Loop through each row
for (var row = 0; row < table.numberRows; row++) {
// Create string with old row label and value of specified statistic
var val = parseFloat(vals[row]);
var old_lab = row_labs[row];
var new_lab = old_lab + " (" + text_before + " " + val.toFixed(decimals) + ")"
new_labs[row] = new_lab;
}
// Set new row labels
table.rowLabels = new_labs;
- In this code, we first define the statistic to use and the format of the text to be appended to each row label.
- Next, we loop through each row and extract the relevant value.
- Each iteration of the loop then appends "(Average = value)" to the existing row label.
6. OPTIONAL: Change statistic_to_add to use a different statistic other than Average.
7. OPTIONAL: Change decimals to include more or less decimal places.
8. OPTIONAL: Change text_before to adjust the text to append to the row label.
9. OPTIONAL: Go to Inputs > STATISTICS > Right and untick Average.
10. Press the blue Play button > OK > OK.
See Also
How to Access Statistics from a Table in a Rule