OrderingBy[list,f]
gives the positions in list at which each successive element of SortBy[list,f] appears.
OrderingBy[list,f,n]
gives the positions in list at which the first n elements of SortBy[list,f] appear.
OrderingBy[list,f,-n]
gives the positions of the last n elements of SortBy[list,f].
OrderingBy[list,f,n,p]
gives positions in list of elements of SortBy[list,f,p].
OrderingBy[f]
represents an operator form of OrderingBy that can be applied to an expression.
OrderingBy
OrderingBy[list,f]
gives the positions in list at which each successive element of SortBy[list,f] appears.
OrderingBy[list,f,n]
gives the positions in list at which the first n elements of SortBy[list,f] appear.
OrderingBy[list,f,-n]
gives the positions of the last n elements of SortBy[list,f].
OrderingBy[list,f,n,p]
gives positions in list of elements of SortBy[list,f,p].
OrderingBy[f]
represents an operator form of OrderingBy that can be applied to an expression.
Details
- list[[OrderingBy[list,f]]] is the same as SortBy[list,f].
- OrderingBy[list,f,seq] is equivalent to Take[OrderingBy[list,f],seq].
- OrderingBy[list,f,All,p] gives the position at which all elements of list appear in SortBy[list,f,p].
- OrderingBy can be used on expressions with any head, not only List.
- OrderingBy[f][list] is equivalent to OrderingBy[list,f].
Examples
open all close allBasic Examples (3)
Find the ordering that sorts a list of strings by their length:
OrderingBy[{"list", "of", "strings"}, StringLength]{"list", "of", "strings"}[[%]]Check that their string lengths are sorted:
StringLength /@ %Find the positions of the 3 smallest elements by absolute value:
OrderingBy[Range[-5, 5], Abs, 3]Find the positions of the 3 largest elements by absolute value:
OrderingBy[Range[-5, 5], Abs, -3]Find the ordering of values in an association:
OrderingBy[<|"a" -> {5, 2}, "b" -> {3, 8}, "c" -> {1, 0}|>, First]Scope (4)
Find the positions of the 3 shortest strings:
OrderingBy[{"dog", "zebra", "donkey", "anteater", "fish"}, StringLength, 3]Find the positions of the 3 longest strings by ordering according to decreasing lengths:
OrderingBy[{"dog", "zebra", "donkey", "anteater", "fish"}, StringLength, 3, Greater]Find the positions of the smallest to largest complex numbers by modulus:
list = {Sqrt[1 + Exp[-10I]], Exp[2 + I], Exp[2 I - 1], Exp[I]}OrderingBy[list, Abs, All, NumericalOrder]list[[%]]//Abs//NUsing canonical sorts them in a different way:
OrderingBy[{Sqrt[1 + Exp[-10]], Exp[2 + I], Exp[2 I - 1], Exp[I]}, Abs, All]list[[%]]//Abs//NFind the ordering of rows of a Tabular object by a given column:
tab = Tabular[{{1, 2}, {2, 1}, {0, 4}}, {"a", "b"}]OrderingBy[tab, "a"]OrderingBy[tab, "b"]Use the operator form of OrderingBy:
OrderingBy[Last][{{a, 2}, {b, 1}, {c, 7}, {d, 5}}]Related Guides
History
Text
Wolfram Research (2019), OrderingBy, Wolfram Language function, https://reference.wolfram.com/language/ref/OrderingBy.html.
CMS
Wolfram Language. 2019. "OrderingBy." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/OrderingBy.html.
APA
Wolfram Language. (2019). OrderingBy. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/OrderingBy.html
BibTeX
@misc{reference.wolfram_2026_orderingby, author="Wolfram Research", title="{OrderingBy}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/OrderingBy.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_orderingby, organization={Wolfram Research}, title={OrderingBy}, year={2019}, url={https://reference.wolfram.com/language/ref/OrderingBy.html}, note=[Accessed: 12-June-2026]}