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:
Method
1. From the toolbar, go to Calculation > Custom Code and draw a box for the output on the page.
2. Paste the below into the R Code editor and modify per the comments:
# specify the table with the data to use for the rankings
# replace table.q5 with your table name
# (you can click on the table to automatically insert its name)
x = table.q5
# make data negative (the rank function ranks smallest number as 1)
x = x*-1
#remove NETs if present, code only keeps row/col names that aren't NET
x = x[rownames(x) != "NET", colnames(x) != "NET"]
# calculate the ranking within each row across the columns and use
# the "average" rank for ties (google the rank function to see other options)
# change 1 to 2 if you'd like to calculate the ranking within each column instead
ranks = apply(x,1,rank, ties.method="average")
# transpose the result back to the original format
table.rank = t(ranks)
3. [Optional]: If using a ranking table with only one column, it's interpreted as only a series of numbers in R can require different code. Use the following code after the x=x*-1 line:
#remove NETs if present, code only keeps names that aren't NET
x = x[names(x) != "NET"]
# calculate the ranking and use the "average" rank for ties
# (google the rank function to see other options)
ranks = rank(x, ties.method="average")
# transpose the result back to the original format
table.rank = t(ranks)
4. Click Calculate if not calculated automatically.
Next
How to Sort Multiple Column Tables Using R