This article describes how to go from a crosstab with averages on the bottom to a table that includes the averages in the column labels:
Requirements
Please note these steps require a Displayr license.
A crosstab with a statistic that has been added to the bottom of the table by using Data > Statistics > Below, that you want to move into the column headers.
Neither of the Row or Column variable sets in your table can have a grid structure (i.e., Number - Grid, Binary - Grid, or Nominal/Ordinal - Multi).
Method
1. Select your table.
2. In the object inspector, go to Appearance > Rules.
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 column labels");
form.setSummary("Add table statistic to column 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 = below_table.get(statistic_to_add);
var col_labs = table.columnLabels;
var new_labs = [];
// Loop through each column
for (var col = 0; col < table.numberColumns; col++) {
// Create string with old column label and value of specified statistic
var val = parseFloat(vals[0][col]);
var old_lab = col_labs[col];
var new_lab = old_lab + "\n (" + text_before + " " + val.toFixed(decimals) + ")"
new_labs[col] = new_lab;
}
// Set new column labels
table.columnLabels = new_labs;
6. On line 7 of the code, specify the statistic that you want to show in the column headers. The default in the script is "Average" Note that some ome statistics may not be available depending on the data type. On line 9, you can change the prefix of the value to indicate the name of the statistic in the column header.
7. OPTIONAL: On line 8, change decimals to include more or less decimal places.
8. Press the Play button > OK > OK.
The code above loops through each column and extracts the relevant value. Then, each iteration of the loop then appends "(Average = value)" to the existing column label after a line break.
See Also
How to Show Below Statistics at the Top of a Table