I would like to sort a matrix in descending order first by the total of each column, then by the total of each row, but without changing their content. For example, if I had:
TableForm[{{0, 0, 1, 1}, {0, 0, 0, 1}, {1, 0, 1, 1}, {1, 1, 1, 1}},
TableHeadings -> {Range[1, 4], Range[1, 4]}]
I want to sort first the columns:
TableForm[{{1, 1, 0, 0}, {1, 0, 0, 0}, {1, 1, 1, 0}, {1, 1, 1, 1}},
TableHeadings -> {Range[1, 4], {"4", "3", "1", "2"}}]
Then the rows:
TableForm[{{1, 1, 1, 1}, {1, 1, 1, 0}, {1, 1, 0, 0}, {1, 0, 0, 0}},
TableHeadings -> {{"4", "3", "1", "2"}, {"4", "3", "1", "2"}}]
The goal is to get as many 1's as possible to the upper-left corner. I added TableHeadings
to this mockup of the desired result simply to show the content of the columns/rows remains the same. If there is a better way other than using the Total
for each column/row that is fine too. Any help is much appreciated!