I have three parallel lists (i.e. the elements in position i of each list are related). I want to sort the first list using the function Sort and make the same changes to the other lists so that I still have parallel lists when finished.
How can I do this?
As an example: Given the lists {2, 3, 1}, {a, b, c}, and {alpha, beta, gamma}, sorting all lists according the first one gives {1, 2, 3}, {c, a, b}, and {gamma, alpha, beta}.
Answer
lists = {list1, list2, list3} = {{1, 3, 2}, {a, b, c}, {x, y, z}};
Another option
SortBy[lists\[Transpose], First]\[Transpose]
{{1, 2, 3}, {a, c, b}, {x, z, y}}
Comments
Post a Comment