- In a numerical list, Ordering[list,n] gives the positions of the n smallest elements. Ordering[list,-n] gives the positions of the n largest elements.
- If there are several smallest elements in list, Ordering[list,1] will give only the position of the one that appears first.
- list[[Ordering[list]]] is the same as Sort[list].
- Ordering[list,seq] is equivalent to Take[Ordering[list],seq].
- Ordering[list,UpTo[n]] returns n positions, or as many as are available.
- Ordering[list,All,p] gives the position at which all elements of list appear in Sort[list,p].
- Ordering can be used on expressions with any head, not only List.
Examplesopen allclose all
Basic Examples (4)
Find the ordering of values in an Association:
Using Ordering this way is much faster for large sets of lists:
Properties & Relations (2)
list[[Ordering[list]]] is equivalent to Sort[list]:
Wolfram Research (2000), Ordering, Wolfram Language function, https://reference.wolfram.com/language/ref/Ordering.html (updated 2015).
Wolfram Language. 2000. "Ordering." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/Ordering.html.
Wolfram Language. (2000). Ordering. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Ordering.html