Placing n Statistics above % Statistics
Jump to navigation
Jump to search
Places the counts (e.g., n) above the percentage statistics.
// A helper function that allows moving an element within an array.
// Thanks to:
// http://stackoverflow.com/questions/5306680/move-an-array-element-from-one-array-position-to-another
Array.prototype.move = function (old_index, new_index) {
if (new_index >= this.length) {
var k = new_index - this.length;
while ((k--) + 1) {
this.push(undefined);
}
}
this.splice(new_index, 0, this.splice(old_index, 1)[0]);
return this; // for testing purposes
};
// Wherever we find an 'n' (sample size) statistic, move it to the top of the list of statistics.
var stats = table.statistics;
// How many stats we've already moved so far.
var moved_stats = 0;
for (var i = 0; i < stats.length; i++) {
if (stats[i] == 'n' || stats[i].substr(-2) == ' n') {
stats.move(i, moved_stats);
moved_stats++;
}
}
table.statistics = stats;
See also
- Table JavaScript and Plot JavaScript for an explanation of how to run this code.
- Table JavaScript and Plot JavaScript Reference for technical information.
- Table JavaScript and Plot JavaScript Examples Library for other examples.
- JavaScript for information about the JavaScript programming language.
- QScript for tools for automating projects using JavaScript.
- JavaScript Variables for detail on how to create new variables in the Variables and Questions tab using JavaScript.