Introduction
This article describes how to go from a crosstab or summary grid table...
...to a table that displays the rank based on the cell percentages. In this example, we are ranking the brand attributes for each cola:
Requirements
A table with rows and columns.
Method
1. Select your table.
2. Copy the table name from Properties > GENERAL > Name.
3. Go to Calculation > Custom Code and paste the below into the R CODE box:
# specify the table
x = table.q5
# make data negative (the rank function ranks smallest number as 1)
x = x*-1
# apply the ranking
ranks = apply(x,1,rank,"average")
# transpose the result back to the original format
table.rank = t(ranks)
The above code pulls in the table using its reference name from step 2 (table.q5). It then adjusts the data to be suitable for use with the rank function, which is applied across the rows using the apply function.
4. OPTIONAL: If you have a NET row and column, you can remove these by updating the fifth line of code as follows:
x = x[-NROW(x),-NCOL(x)]*-1
The above removes the last row and last column from the table.
5. OPTIONAL: If you'd like to create the ranks within each column instead of each row, change the ranks line to the following:
ranks = apply(x,2,rank,"average")
See Also
How to Work with R in Displayr
Comments
0 comments
Article is closed for comments.