This article describes how to go from an unsorted table...
...to a table that is sorted on a particular column (e.g., Male).
Requirements
One of the following:
- A crosstab with one question selected in rows and one selected in columns.
- A summary table with at least two rows and one column.
Please note this requires the Data Stories module or a Displayr license.
Method
1. Select your table.
2. Go to General > GENERAL > Name and copy the table name.
3. Select Calculation > Custom Code.
4. In the object inspector, go to Data > R CODE.
5. Add a line to the code that defines the table as table = table_name
using the table_name as copied from step 2.
6. Add another line to that code table[order(table[,column_name], decreasing = TRUE),]
where column_name is the name of the column you wish to sort by in descending order. Instead of the column name, you can also use the column index (e.g., "1" for the first column, "2" for the second column, etc.)
7. OPTIONAL: to show the table in ascending order replace decreasing = TRUE with decreasing = FALSE.
This example code takes a table called table.Preferred.cola.by.D3.Gender and sorts it in descending order by the Male column:
table = table.Preferred.cola.by.D3.Gender
table = table[order(table[,"Male"], decreasing = TRUE),]
The below example code uses the same table and sorts it in ascending order by the first column containing data (Male column).
table = table.Preferred.cola.by.D3.Gender
table = table[order(table[,1], decreasing = FALSE),]