This example code can be used in a custom QScript. It uses table.calculateOutput() to calculate the table's statistics, then process them and extract the row heading that contains the lowest p-value statistic. It then changes the table's name in the report tree so that when exported, the title will include this information.

## Technical details

This snippet is only applicable to tables using exception testing.

## Method

// Change the name of the table to include the category which has the lowest (most significant) p-value. // Calculate the statistics. var output = table.calculateOutput(); // Get the array of p-values. var pvalues = output.get('p'); // Keep track of which row contains the lowest p-value. var lowest_p; var lowest_row; for (var row = 0; row < output.numberRows; row++) for (var column = 0; column < output.numberColumns; column++) { var p = pvalues[row][column]; if (row == 0 && column == 0) { lowest_p = p; lowest_row = row; } else { if (p < lowest_p) { lowest_p = p; lowest_row = row; } } } // Now 'lowest_row' holds the number of the row with the lowest p value. // Lets extract its label from the output. var lowest_row_label = output.rowLabels[lowest_row]; // Change the name of the table to include the lowest row information. table.name = table.name + ' (Most significant: ' + lowest_row_label + ', p = ' + lowest_p + ')';

## See also

- QScript for an explanation of how to run this code.
- QScript Examples Library for other examples.
- QScript Reference for technical information.
- JavaScript for information about the JavaScript programming language.
- Table JavaScript and Plot JavaScript for tools for using JavaScript to modify the appearance of tables and charts.
- JavaScript Variables for detail on how to create new variables.