PRODUCTS
Products Overview
Mathematica
Mathematica for Students
Mathematica Home Edition
Wolfram
CDF Player
(free download)
Computable Document Format (CDF)
web
Mathematica
grid
Mathematica
Wolfram
Workbench
Mathematica
Add-Ons
Wolfram|Alpha Products
SOLUTIONS
Solutions Overview
Engineering
Aerospace Engineering & Defense
Chemical Engineering
Control Systems
Electrical Engineering
Image Processing
Industrial Engineering
Materials Science
Mechanical Engineering
Operations Research
Optics
Petroleum Engineering
Biotechnology & Medicine
Bioinformatics
Medical Imaging
Finance, Statistics & Business Analysis
Actuarial Sciences
Data Analysis & Mining
Econometrics
Economics
Financial Engineering & Mathematics
Financial Risk Management
Statistics
Software Engineering & Content Delivery
Authoring & Publishing
Interface Development
Software Engineering
Web Development
Science
Astronomy
Biological Sciences
Chemistry
Environmental Sciences
Geosciences
Social & Behavioral Sciences
Design, Arts & Entertainment
Game Design, Special Effects & Generative Art
Education
STEM Education Initiative
Higher Education
Community & Technical College Education
Primary & Secondary Education
Students
Technology
Computable Document Format (CDF)
High-Performance & Parallel Computing (HPC)
See Also: Technology Guide
PURCHASE
Online Store
Other Ways to Buy
Volume & Site Licensing
Contact Sales
Software
Service
Upgrades
Training
Books
SUPPORT
Support Overview
Knowledge Base
Learning Center
Community & Forums
Training & Free Seminars
Does My Site Have a License?
Wolfram User Portal
COMPANY
About Wolfram Research
News & Events
Wolfram Blog
Partnerships
Employment Opportunities
History of
Mathematica
Stephen Wolfram's Home Page
Contact Us
OUR SITES
All Sites
Wolfram|Alpha
Demonstrations Project
MathWorld
Integrator
Wolfram Functions Site
Mathematica Journal
Wolfram Media
Wolfram
Tones
Wolfram Science
Stephen Wolfram
DOCUMENTATION CENTER SEARCH
New to
Mathematica
?
Find your learning path
»
Mathematica
>
Core Language
>
List Manipulation
>
Rearranging & Restructuring Lists
>
SortBy
>
Mathematica
>
Data Manipulation
>
Handling Arrays of Data
>
Rearranging & Restructuring Lists
>
SortBy
>
Mathematica
>
Data Manipulation
>
Image Processing & Analysis
>
Basic Image Manipulation
>
Handling Arrays of Data
>
Rearranging & Restructuring Lists
>
SortBy
>
BUILT-IN MATHEMATICA SYMBOL
Sort
Ordering
OrderedQ
Tally
Nearest
See Also »
|
Math & Counting Operations on Lists
Numerical Data
Rearranging & Restructuring Lists
New in 6.0: List Manipulation
More About »
SortBy
SortBy
sorts the elements of
list
in the order defined by applying
f
to each of them.
MORE INFORMATION
SortBy
sorts the
so that the
lie in canonical order.
If some of the
are the same, then the canonical order of the corresponding
is used.
SortBy
breaks ties by successively using the values obtained from the
.
SortBy
uses the canonical ordering described in the notes for
Sort
.
SortBy
can be used on expressions with any head, not only
List
.
EXAMPLES
CLOSE ALL
Basic Examples
(2)
Sort a list of lists by the last element of each sublist:
Sort by the total of each sublist:
Sort a list of integers by their values modulo 3:
Sort a list of lists by the last element of each sublist:
In[1]:=
Out[1]=
Sort by the total of each sublist:
In[2]:=
Out[2]=
Sort a list of integers by their values modulo 3:
In[1]:=
Out[1]=
Scope
(4)
Sort by numerical value:
The default order ranks these symbolically:
Sort by absolute numerical value:
Slightly faster way:
Sort by
Re
,
Im
,
Arg
, and
Abs
:
Sort by date:
Generalizations & Extensions
(1)
SortBy
can be used on expressions with any head:
Applications
(2)
Show the top 10 countries according to different criteria:
Sort the first 10 countries in alphabetical order by population:
Sort the first 10 countries in alphabetical order by area:
Sort mathematically equivalent expressions by different criteria:
Sort by
LeafCount
:
Sort by size of error for numerical evaluation with machine numbers at
:
Properties & Relations
(1)
SortBy
is equivalent to
Sort
[{
f
[#], #}&/@
e
][[
All
, -1]]
:
SEE ALSO
Sort
Ordering
OrderedQ
Tally
Nearest
MORE ABOUT
Math & Counting Operations on Lists
Numerical Data
Rearranging & Restructuring Lists
New in 6.0: List Manipulation
New in 6 | Last modified in 7