This QScript creates a new filter or each selected question category.
Examples
Displayr: How to Create a Binary Filter from Selected Data
Q: Automate > Browse Online Library > Filter > Filter from Selected Data
Technical details
In Displayr, you must select a Variable set from the Data Sets tree to run the script.
In Q, you can preselect a table on the Outputs tab or a question on the Variables and Questions tab, and the script will run on the pre-selected table/question (assuming they're of a permissible type - see below).
If you have nothing selected, you will be presented with a list of appropriate questions in the data set, and you can select the questions you wish to create filters from.
This list is restricted to questions of the type Nominal: Mutually exclusive Categories, Nominal or Ordinal Multi - Grid, Binary - Multi: Non mutually exclusive Categories, Binary - Grid, and Binary - Multi (Compact).
The filters for a question are combined into a new question. In Displayr, the new variable set appears in the Data Sets tree, and in Q, a table is added to your report to show each of these new questions.
For Binary - Grid questions, a copy of the question is made, and each variable is set as a filter. For all other question types, this QScript will identify changes that have been made in the tables (e.g., merging and renaming of categories), and the filters that are created will reflect those changes.
Code
includeWeb('QScript Questionnaire Functions');
includeWeb('QScript Value Attributes Functions');
includeWeb('QScript Utility Functions');
includeWeb('QScript Selection Functions');
includeWeb('QScript Functions to Generate Outputs');
includeWeb('QScript Data Reduction Functions');
includeWeb('QScript Functions for Combining Categories');
includeWeb('QScript Functions for Filters');
createFiltersFromSelectedData()
function createFiltersFromSelectedData() {
const web_mode = inDisplayr();
const allowed_types = ["Nominal", "Ordinal", "Nominal - Multi", "Ordinal - Multi", "Binary - Multi",
"Binary - Multi (Compact)", "Binary - Grid"];
let selected_questions = selectInputQuestions(allowed_types);
if (!selected_questions)
return false;
if (!areQuestionsValidAndNonEmpty(selected_questions))
return false;
let filter_questions = selected_questions.map(createFiltersForAllCategories);
filter_questions = filter_questions.filter(function (q) { return q != null; });
if (filter_questions.length == 0) {
log("The selected questions contain no data, or are not appropriate.");
return false;
}
moveQuestionsToHoverButtonIfShown(filter_questions);
reportNewRQuestion(filter_questions, "Filters");
return true;
}Before the 15th of December, 2015, this page was known as Create New Variables - Create Filters from Selected Data.