If you have a categorical array, you may like to sort it based on a subtotal you create.
For example, in the summary view of the array below (Brand Attitude), you can see the categories (sub-variables) have been sorted (descending) on the subtotal (net) called Top 2 Box.
This is simple to achieve in R. It assumes you've made the subtotal already on the categorical array.
How to run the R code:
In the below, all you need to change is the first two lines: the alias of the variable, and the label of the subtotal. Of course, you need to have logged in and loaded your dataset first.
variable <- "Brandattitude"
subtotal <- "Top 2 Box"
x <- prop.table(crtabs(data = ds, as.formula(paste0("~", variable))))
order <- names(sort(x[,subtotal], decreasing = TRUE))
subvariables(ds[[variable]]) <- subvariables(ds[[variable]])[order]