This article describes how to create a frequency table in Q. A frequency table shows the number of times each unique value appears in one or more variables. They are commonly used for reporting (e.g., providing the data to appear in charts) and for data cleaning.
A category variable that you want to create a table showing counts and percentages.
- From the Blue drop down menu, select the variable you want to display in a table
- From the Brown drop down menu, ensure that SUMMARY is selected.
- Right-click the cell in the upper-left corner and select Statistics - Cells > n
Creating a Frequency Table from code
// Working on Phone.sav, this creates a new frequency table of Age. var t = project.report.appendTable(); t.primary = project.dataFiles.getQuestionByName('Age'); t.secondary = "SUMMARY";
- 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.getQuestionByName('Age'); t.secondary = project.dataFiles.getQuestionByName('Gender');