Abbreviate Month Labels for a Date/Time Question
Displayr - How to Abbreviate Month Labels in Tables
Q - How to Abbreviate Month Labels in Tables
// Abbreviate month labels in rows and columns of table
// All labels must be months for any replacements to be made
var row_labels = table.rowLabels;
var col_labels = table.columnLabels;
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
// Check row labels and update
var split_labels = row_labels.map(function (str) { return str.split(" ")[0]; });
if (split_labels.every( function (str) { return months.indexOf(str) > -1; })) {
split_labels = split_labels.map(function (str) { return str.substring(0, 3); });
table.rowLabels = split_labels;
}
// Check column labels and update
var split_labels = col_labels.map(function (str) { return str.split(" ")[0]; });
if (split_labels.every( function (str) { return months.indexOf(str) > -1; })) {
split_labels = split_labels.map(function (str) { return str.substring(0, 3); });
table.columnLabels = split_labels;
}
Adding Sample Size to the Column Labels
Displayr - How to Add Sample Size to Column Labels in a Table |
var do_java; // Prevent an error when no below_table exists
try {
do_java = below_table.availableStatistics.indexOf('Column n') != -1;
} catch (e) {
do_java = false;
}
if (table.numberColumns > 1 && do_java) {// If this table has the 'Column n' statistic
var column_ns = below_table.get('Column n');// Get the column n values
if (column_ns.length == 1)
column_ns = column_ns[0];
var column_labels = table.columnLabels;// Get the standard column labels.
for (var column = 0; column < table.numberColumns; column++) {// For each column...
// Adjust the label to include the column name and column n, on new lines.
column_labels[column] = column_labels[column] + '\r\n' + 'n = ' + column_ns[column];
}
// Set the adjusted column labels.
table.columnLabels = column_labels;
}
How to Add Sample Size to Column Labels in a Table
Displayr - How to Add Sample Size to Column Labels in a Table
Q - How to Add Sample Size to Column Labels in a Table
var do_java; // Prevent an error when no below_table exists
try {
do_java = below_table.availableStatistics.indexOf('Column n') != -1;
} catch (e) {
do_java = false;
}
if (table.numberColumns > 1 && do_java) {// If this table has the 'Column n' statistic
var column_ns = below_table.get('Column n');// Get the column n values
if (column_ns.length == 1)
column_ns = column_ns[0];
var column_labels = table.columnLabels;// Get the standard column labels.
for (var column = 0; column < table.numberColumns; column++) {// For each column...
// Adjust the label to include the column name and column n, on new lines.
column_labels[column] = column_labels[column] + '\r\n' + 'n = ' + column_ns[column];
}
// Set the adjusted column labels.
table.columnLabels = column_labels;
}
How to Add a Column Header Footnote Indicating Small Sample Sizes
Displayr - How to Add a Column Header Footnote Indicating Small Sample Sizes
Q - How to Add a Column Header Footnote Indicating Small Sample Sizes
var column_ns = table.get('Column n');// Get the Column N statistics.
var column_labels = table.columnLabels;// Get the column labels.
var footnotes = table.extraFooters;// Make a list of extra footnotes.
for (var column = 0; column < table.numberColumns; column++) {// For each column...
var column_n = column_ns[0][column];// Get the column n statistic (from the cell in the first row).
if (column_n < 30) {
footnotes.push('* column "' + column_labels[column] + '" has less than 30 respondents.');// Add an extra footnote.
column_labels[column] += '*';// Put a marker on this column's label.
}
}
table.columnLabels = column_labels;// Store the adjusted column labels and footnotes.
table.extraFooters = footnotes;
How to Add a Footnote for Cells with Small Sample Sizes
Displayr - How to Add a Footnote for Cells with Small Sample Sizes
Q - How to Add a Footnote for Cells with Small Sample Sizes
if (table.availableStatistics.indexOf('Column n') != -1)
table.addFootNoteForCellsLessThan('Column n', 20, '*', '* sample size < 20');
else
table.addFootNoteForCellsLessThan('Base n', 20, '*', '* sample size < 20');
How to Automatically Remove NETs From Tables
Displayr - How to Automatically Remove NETs from Tables
Q - How to Automatically Remove NETs from Tables
includeWeb("Table JavaScript Utility Functions");
// Delete any NET columns
var n_deleted_cols = 0;
table.netColumns.forEach(function (net_col) {
deleteColumnComplete(net_col - n_deleted_cols);
n_deleted_cols++;
});
// Delete any NET rows
var n_deleted_rows = 0;
table.netRows.forEach(function (net_row) {
deleteRowComplete(net_row - n_deleted_rows);
n_deleted_rows++;
});
How to Blank Table Cells with Small Sample Sizes
Displayr - How to Blank Table Cells with Small Sample Sizes
Q - How to Blank Table Cells with Small Sample Sizes
var min_sample_size = 10
var column_ns = table.get('Column n');// Get column sample sizes.
var extra_footers = table.extraFooters;// Store the extra footnotes we generate for each blank column.
for (var column = 0; column < table.numberColumns; column++) {// loop through the columns
for (var row = 0; row < table.numberRows; row++) {
// Get the sample size for this cell
var column_n = column_ns[row][column];
// If the column's sample size is less than min_sample_size, make each cell in the column blank.
if (column_n < min_sample_size) {
table.blankCell(row, column);
// Also, add a footnote that explains why some columns are missing.
extra_footers.push('Column "' + table.columnLabels[column]
+ " is blank because less than " + min_sample_size + " people were asked the question.");
}
}
}
// Set the extra footnotes.
table.extraFooters = extra_footers;