PRODUCTS
Mathematica
Mathematica Home Edition
Mathematica for Students
Mathematica for the Classroom
grid
Mathematica
Wolfram Lightweight Grid Manager
web
Mathematica
Mathematica Player
(free download)
Mathematica Player Pro
Wolfram
Workbench
Mathematica
Applications
SOLUTIONS
Engineering
Aerospace Engineering & Defense
Chemical Engineering
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
Higher Education
Precollege Education
Students
Technology
Interactive Deployment
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
FOR USERS
All User Resources
Product Registration
Technical Support
Customer Service
Developer Support
Does My Site Have a License?
Free Seminars
Learning Center
Training
Custom Group Seminars
Documentation & Examples
Tutorial Screencasts
Video Gallery
Demonstrations Project
Education Portal
Student Resources
COMPANY
About Wolfram Research
News & Events
Wolfram Blog
Employment Opportunities
History of
Mathematica
Stephen Wolfram's Home Page
Contact Us
OUR SITES
Wolfram|Alpha
Demonstrations Project
Wolfram Blog
MathWorld
Integrator
Wolfram Functions Site
Mathematica Journal
Wolfram Library Archive
Wolfram
Tones
Wolfram Science
Stephen Wolfram
DOCUMENTATION CENTER SEARCH
Mathematica
>
Core Language
>
List Manipulation
>
Rearranging & Restructuring Lists
>
Mathematica
>
Data Manipulation
>
Handling Arrays of Data
>
Rearranging & Restructuring Lists
>
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
[
list
,
f
]
sorts the elements of
list
in the order defined by applying
f
to each of them.
MORE INFORMATION
SortBy
[{
e
1
,
e
2
,
e
3
,
...
},
f
]
sorts the
e
i
so that the
f
[
e
i
]
lie in canonical order.
If some of the
f
[
e
i
]
are the same, then the canonical order of the corresponding
e
i
is used.
SortBy
[
list
, {
f
1
,
f
2
,
...
}]
breaks ties by successively using the values obtained from the
f
i
.
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:
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)
Generalizations & Extensions
(1)
Applications
(2)
Properties & Relations
(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
RELATED LINKS
Demonstrations with SortBy
(
Wolfram Demonstrations Project
)
New in 6 | Last modified in 7