Sorting list of listsJMP12
How to sort a list of lists by one list in the list of lists?
For example I want to sort by the numeric part of this list.
I know I could iterate or make a table to sort this way, but is there a one-liner I don't know of? I feel like there must be an easier way to do it.
list = {{"a", "b", "c", "d"}, {2, 3, 4, 1}};a,2
b,3
c,4
d,1
(list[1] and list[2] sorted by list[2])
{{"d", "a", "b", "c"}, {1, 2, 3, 4}};d,1
a,2
b,3
c,4
Advanced Statistical ModelingData Blending and CleanupMass CustomizationRe: Sorting list of listsThanks this is exactly what I was looking for.
Re: Sorting list of listsYou probably want the rank function. See Sorting Lists .
list = {{"a", "b", "c", "d"}, {2, 3, 4, 1}};
r = rank(list[2]);
list[1] = list[1][r];
list[2] = list[2][r];
show(list);
list = {{"d", "a", "b", "c"}, {1, 2, 3, 4}};
rank() returns a vector of indexes that retrieve the elements in order.