I have a long table in this form:
A = {{a, 1}, {c, 2}, {b, 5}, {c, 1}, {a, 14}, {b, 7}, {b, 10}, {c, 6}, {a, 4}}
and I want to order it by the second column, but first all with an "a" in the first element should be ordered. And then by order of appearance. It should look like this:
{{a, 1},{a, 4},{a, 14},{c, 1},{c, 2},{c, 6},{b, 5},{b, 7},{b, 10}}
SortBy[A, #[[2]] &]
would sort the second column, ignoring the first.
Any ideas? Maybe a for-loop?
SortBy[A, {#[[1]] &, #[[2]] &}]
? $\endgroup$ – J. M. will be back soon♦ Mar 31 '17 at 12:50Sort[A]
? $\endgroup$ – Artes Mar 31 '17 at 12:52Sort /@ GatherBy[A, First]
. $\endgroup$ – Artes Mar 31 '17 at 12:59Sort /@ GatherBy[A, First]
was what I wanted. The other two answers would also sort the first element alphabetically. I wanted it by order of appearance. $\endgroup$ – drcyberz Mar 31 '17 at 13:34