Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #1725
| From | Albert Retey <awnl@gmx-topmail.de> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: SortBy |
| Date | 2011-04-16 11:38 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <iobv34$bgp$1@smc.vnet.net> (permalink) |
| References | <io8to0$qbf$1@smc.vnet.net> |
Am 15.04.2011 09:56, schrieb graser:
> Dear Mathematica group,
>
> I have a simple question for you.
>
> Let's say there is a list like
>
> KS = {{300, 48, 2}, {500, 23, 5}, {120, 55, 7}, {40, 32, 1}};
>
> I want to sort it by second element.
>
> I can use
>
> Sort[KS, #2[[2]]> #1[[2]]&]
>
> It gives out like
>
> {{500, 23, 5}, {40, 32, 1}, {300, 48, 2}, {120, 55, 7}}
>
> But if I want to use SortBy, how to do that?
>
While there are functions First and Last, there is no Second and Third,
but maybe that's an inexpensive possibility to increase the number of
functions in the next version even more :-).
But you can use a pure function:
SortBy[KS, #[[2]] &]
hth,
albert
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
SortBy graser <graser@gmail.com> - 2011-04-15 07:56 +0000 Re: SortBy Peter Pein <petsie@dordos.net> - 2011-04-16 11:34 +0000 Re: SortBy Albert Retey <awnl@gmx-topmail.de> - 2011-04-16 11:38 +0000 Re: SortBy Peter Breitfeld <phbrf@t-online.de> - 2011-04-16 11:38 +0000 Re: SortBy "Sjoerd C. de Vries" <sjoerd.c.devries@gmail.com> - 2011-04-16 11:39 +0000 Re: SortBy Helen Read <readhpr@gmail.com> - 2011-04-16 11:32 +0000
csiph-web