5
$\begingroup$

I have sorted the data firstly by the 3rd column and then by the 2nd column as below:-

a = RandomInteger[20, {30, 3}]
SortBy[a, {#[[3]], #[[2]]} &]

As you can see, now they are both sorted in ascending order. But I need the 3rd column to be sorted by descending order, while the 2nd should be sorted in ascending order. What should I do?

Many thanks!

$\endgroup$
5
$\begingroup$

Maybe

SortBy[a, {-#[[3]], #[[2]]} &];

?

$\endgroup$
  • $\begingroup$ Thanks... I was stuck at how to combine the Greater option with it... $\endgroup$ – H42 Jun 15 '18 at 22:58
  • $\begingroup$ You're welcome. $\endgroup$ – Henrik Schumacher Jun 15 '18 at 23:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.