This article describes how to extract statistics from a table via a Rule that can then be used for further calculations.
In each case, only the statistics that are currently being displayed in a table will be included.
If you wish to return a list of all statistics that can be computed from this table, you can instead append the
availableStatistics property to the appropriate table statistic location:
Note, not all tables will have each of these types of statistics:
- A Nominal, Ordinal, Binary - Multi , Binary - Multi (Compact) or Number - Multi summary table will only have cell and below statistics.
- A Nominal - Multi or Ordinal - Multi summary table will only have cell and right statistics.
- A crosstab, Binary - Grid or Number - Grid will include cell, right and below statistics.
- When you switch rows and columns, the right and below statistics will be reversed.
You can check whether right or below statistics exist by using the below functions which will return true or false:
Note, you must include
Referencing values from a statistic
You can return the values of a statistic by using the
var cell_vals = table.get("%");
var right_vals = right_table.get("Sum");
var below_vals = below_table.get("Average");
In this example, cell_vals will, for example, ‘get’ the statistic values for every cell in the table across all rows and columns.
getOriginalName. In the below example, we return the original name for Column Sample Size (which is Column n) and pass this instead into the
var stat = getOriginalName("Column Sample Size");
var below_vals = below_table.get(stat);
If you want to have a more flexible Rule that uses the primary statistic, you can combine the
get function with the
The format of the
get function is a two-dimensional array, where the rows are in the first index and the columns in the second index. So an array of cell statistics in a table might look like this:
[[col1-row1, col2-row1, ...],[col1-row2, col2-row2, ...]]
array[row index][column index] reference format,
vals in this case would be the first table cell, that is col1-row1 for the array.
Note that for one-dimensional SUMMARY tables, a two-dimensional array will still be returned, with only one column in the second dimension. The value type will be based on whether the returning statistic is text or numeric.