Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Sort by multiple columns at the same time
ResourceFunction["MultiColumnSort"][matrix] sorts matrix by the elements of the first column into canonical order. | |
ResourceFunction["MultiColumnSort"][matrix,{{column1,order1},{column2,order2},…}] sorts multiple columns by ascending or descending order at the same time. The priority of the columns to be sorted is column1,column2, …. |
A sample matrix:
| In[1]:= |
| Out[2]= | ![]() |
Sort the first column elements of matrix into canonical order:
| In[3]:= |
| Out[3]= | ![]() |
Sort the first column first in ascending order, then the second column in descending order, and finally the third column in ascending order:
| In[4]:= |
| Out[4]= | ![]() |
With CaseOrdering→"LowerFirst", the lowercase form of a character is sorted before its uppercase form:
| In[5]:= | ![]() |
| Out[6]= | ![]() |
With CaseOrdering→"UpperFirst", the uppercase form is sorted before the lowercase form:
| In[7]:= |
| Out[7]= | ![]() |
The default value of IgnorePunctuation is False:
| In[8]:= | ![]() |
| Out[9]= | ![]() |
IgnorePunctuation→True sorts after removing all punctuation marks and whitespace:
| In[10]:= |
| Out[10]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License