Introduction
This article describes how to go from a table constructed from a Pick One - Multi question in the blue drop-down and SUMMARY in the brown drop-down, with averages on the right...
...to a table that includes the averages in the row labels:
Method
1. Select your table.
2. Go to Automate > Custom Rule.
3. 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 (Average, in the example provided in the table above) 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.
4. OPTIONAL: Change statistic_to_add to use a different statistic other than Average.
5. OPTIONAL: Change decimals to include more or less decimal places.
6. OPTIONAL: Change text_before to adjust the text to append to the row label.
7. OPTIONAL: Right-click your table > Statistics - Right and untick Average.
8. Press the Play button > Close > OK > OK.