# Questions tagged [sorting]

Questions on the sorting/ordering functions of Mathematica (Sort, SortBy, Ordering, etc.).

350 questions
Filter by
Sorted by
Tagged with
415 views

### How to sort first two numbers in sublists

Given t7 = t8 = {{3, 5, 1}, {19, 2, 9}, {4, 3, 1}, {19, 0, 8}}; I want to Sort the first two numbers in each sublist and keep ...
65 views

### Rearrange a matrix with new Table Headings-List

I have used a procedure to rearrange my data in a more appropriate way for data analysis such that more similar elements lie next to each other and dissimilar ones far apart. Let's say I have a 5x5 ...
53 views

### How to sort arguments in descending order in an orderless function

If I define an operator to be orderless SetAttributes[CirclePlus,Orderless] It puts the arguments into canonical sorting, i.e. ...
66 views

### Does default 'Sort' generate always the same result? [closed]

Does default 'Sort' output always the same result regardless if we change its order? Suppose that L = {E1,E2,E3,E4,E5} (*here E1,..,E5 means any possible ...
152 views

Heres an MWE ...
353 views

### How to use Intersection[] but keep the original list order

I want to keep the original order of l1: ...
61 views

### Making function $S$ such that inputs as an list $\{1,3,2,4, \}$ and produces $s_{1234}$

I want to make $S[\{,\cdots, \}]$ as follows First input of $S$ is given list $\{1,2,3,\cdots, n\}$ and it produces $s_{123\cdots n}$ Further, if the ordering of the list is given differently, still ...
85 views

### Swapping items in a table

I have a code that generates various tables like ...
84 views

### Undesired side effect of SortBy [duplicate]

After long searching, I noticed that the SortBy[list,f] function has an annoying side effect: If the function f yields the same value for consecutive elements of the list, those are still sorted using ...
52 views

### How to obtain the grouped separate line curves from the disorder data?

The sample point data and codes are listed as following. The point-image tells us that the data can be divided into nine groups. However, why are they divided into two groups by ...
61 views

### Defining elements of matrix as a function of two variables (the position $(i,j)$ ) [closed]

I have the following array, which generated from grayscale image data,:  \left( \begin{array}{cccccccc} 162 & 162 & 162 & 161 & 162 & 157 & 163 & 161 \\ 162 & 162 &...
273 views

### On the ordering of the vertices of a polygon

Writing: pts = {{1, 0}, {2, 0}, {2, 3}, {3, 3}, {3, 4}, {0, 4}, {0, 3}, {1, 3}, {1, 0}}; Graphics[{Red, Point[pts], Blue, Line[pts]}] we get: and all of this ...
37 views

### Mismatch for Ordering[list,1] and Position[list, Min[list]] [closed]

I am using Ordering[list, 1] to get the position of the minimum of a list, but in this example ...
160 views

### Combine SortBy with ReverseSortBy

Suppose I have a dataset, which I want to sort according to two criteria. However, I want the first criteria to be sorted ascending, and the second descending. This would require to somehow combine ...
98 views

### how to sum a column after SortBy[...]

Given a dataset: ...
49 views

92 views

### Nonrepetitive representation of a group of lists (with sharing members)

Background: Lets first construct a square graph (the ha and second points define to implement periodic boundary condition): ...
379 views

### List of tuples without duplicates & repeated values [duplicate]

Given some number nand set of values vals, I want to obtain all the tuples/permutations of size ...
44 views

### Confusion about the sorting function

The following one-dimensional array can be sorted well: Sort[{Infinity, 10, 2, 1, -4}, #1 < #2 &] But the following two-dimensional array cannot sort the <...
109 views

### Ordering a list of rules by its 4 last elements of LHS

I have a list of rules such as ...
94 views

### Sort a nested Association by another Association [closed]

I have a nested association of numerous pixel values sorted by sample date (e.g. 20190422C) and futher by a strain percentage (e.g. 0, 30, 50). I want to sort it even further using and Association of ...
135 views

### How do you reorder a sublist of strings, within a list?

I have a list that looks like this: ...
252 views

### Ordering Problem With VoronoiMesh

Imagine I want to model 2D cells moving in a tissue. Consider, as an example, Lloyd's relaxation algorithm. Using VoronoiMesh I'm able to mimic some cell movement. ...
558 views

### Best way to insert element into an ordered list at the correct position?

Suppose I have an ordered list orderedList and I want to write some code that will involve regularly inserting new elements into ...
27 views

### Arranging terms by the values of numerical coefficients

I have a list with elements of the form myList = {c1 F1, c2 F2, c3 F3, ...} where c1, c2, ... are explicitly integers, and ...