Modify Cell Content - Change Missing Data (NaN) Symbol

From Q
Jump to navigation Jump to search


This rule replaces NaN with a user-defined symbol (e.g., -).

Example

ChangingNaNRule.png

How to apply this rule

For the first time in a project

  • Select the table(s)/chart(s) that you wish to apply the rule to.
  • Start typing the name of the Rule into the Search features and data box in the top right of the Q window.
  • Click on the Rule when it appears in the QScripts and Rules section of the search results.

OR

  • Select Automate > Browse Online Library.
  • Choose this rule from the list.

Additional applications of the rule

  • Select a table or chart that has the rule and any table(s)/chart(s) that you wish to apply the rule to.
  • Click on the Rules tab (bottom-left of the table/chart).
  • Select the rule that you wish to apply.
  • Click on the Apply drop-down and choose your desired option.
  • Check New items to have it automatically applied to new items that you create. Use Edit > Project Options > Save as Template to create a new project template that automatically uses this rule.

Removing the rule

  • Select the table(s)/chart(s) that you wish to remove the rule from.
  • Press the Rules tab (bottom-right corner).
  • Press Apply next to the rule you wish to remove and choose the appropriate option.

How to modify the rule

  • Click on the Rules tab (bottom-left of the table/chart).
  • Select the rule that you wish to modify.
  • Click Edit Rule and make the desired changes. Alternatively, you can use the JavaScript below to make your own rule (see Customizing Rules).

JavaScript

Simpler code, which replaces the symbol but does not create the controls, is here.

includeWeb('Table JavaScript Utility Functions');

excludeRTables();
table.requireNumericTable();

// Set up controls for user input.
form.setHeading('Changing the Missing Data (NaN) Symbol');
let description = form.newLabel("Choose a symbol or text to use in table cells instead of showing 'NaN'");
description.lineBreakAfter = true;
let label_text = form.newLabel('Replace with:');
let text_box = form.newTextBox('text');
text_box.setDefault('-');
form.setInputControls([description, label_text, text_box]);
let text = text_box.getValue();
form.setSummary('Replace missing data (NaN) with "' + text + '"');

table.showMissingAs(text);

See also