Suppose I have the following matrix whose row elements are given by the data listed below.
data = {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, {0, 0, 0,
0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0,
1, 1, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0,
0, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
head = {{S0, S1, S2, S3, S4, S5, S6, S7, S8}, {c1, c2, c3, c4, c5, c6,
c7, c8, c9, c10, c11, c12, c13, c14, c15, c16}};
Join[Transpose[{Join[{""}, head[[1]]]}], Join[head[[{2}]], data],
2] // Grid
rownames = {S0, S1, S2, S3, S4, S5, S6, S7, S8};
colnames = {c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13,
c14, c15, c16};
groups1 = GroupBy[Thread[rownames -> data], Last -> First]
Values[groups1]
In this case, it turns out that rows (S1, S8), (S2, S3, S4), (S5, S6, S7) as row vectors have equal element values that are associated with certain column names. The above code produces this output
<|{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -> {S0}, {0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -> {S1, S8}, {0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0} -> {S2, S3, S4}, {0, 0, 0, 0, 1,
0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0} -> {S5, S6, S7}|>
{{S0}, {S1, S8}, {S2, S3, S4}, {S5, S6, S7}}
The output I'm looking for are which columns this output is associated with; specifically, I'm looking for an output like this:
{{{c1}, S0}, {{c6}, S1, S8}, {{c12}, S2, S3,
S4}, {{c5, c9, c10, c11, c12}, S5, S6, S7}}
Any help is most appreciated!!