The following list has some elements that are labeled. For example {1, 2} -> 1, {-1, 3} -> 3
, etc:
list = {{1, 2}, {-1, 3}, {5, 6}, {-3, 4}, {7, 8}, {-9, 1}, {0, 1}};
labels = {1, 3, 2, 1, 2, 1, 3};
What is a good way to gather list
's elements clustered according to their labels?
clusters = {{{1 ,2}, {-3, 4}, {-9, 1}}, {{5, 6}, {7, 8}}, {{-1, 3}, {0, 1}}}
Extract[list, Position[labels, #]] & /@ Union@labels
$\endgroup$