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$
0

1 Answer 1

6
$\begingroup$

Maybe

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

?

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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