Creating a Frequency Table
Jump to navigation
Jump to search
Adds a new table to the Report containing a SUMMARY of a Pick One question.
// Working on Phone.sav, this creates a new frequency table of Age.
var t = project.report.appendTable();
t.primary = project.dataFiles[0].getQuestionByName('Age');
t.secondary = "SUMMARY";
Note that:
- project.report.appendTable() tells Q to append a table to the project’s report tree.
- var t = tells Q to refer to the table that has been created as t in the rest in the script.
- The second and third line of the code tell Q which questions to select in the blue and brown drop-downs respectively. In this example, we have created a frequency table by selecting SUMMARY in the brown drop-down. To instead create a crosstab of age by gender:
var t = project.report.appendTable();
t.primary = project.dataFiles[0].getQuestionByName('Age');
t.secondary = project.dataFiles[0].getQuestionByName('Gender');
See also
- Next worked example.
- Preliminary Project Setup - Summary Tables for a QScript to generate a summary table for each question in your project.
- QScript for an explanation of how to run this code.
- QScript Examples Library for other examples.
- QScript Reference for technical information.
- JavaScript for information about the JavaScript programming language.
- Table JavaScript and Plot JavaScript for tools for using JavaScript to modify the appearance of tables and charts.
- JavaScript Variables for detail on how to create new variables in the Variables and Questions tab using JavaScript.