2
$\begingroup$

Given the data below:

ClearAll[centralityTable,community];
centralityTable={{"segw", 5, 0.583333, 0.306122, 0.0345883}, {"min", 8, 25.5, 
  0.517241, 0.0502948}, {"ma6", 6, 2., 0.517241, 0.0138588}, {"swhl", 
  11, 28.95, 0.625, 0.0613707}, {"scst", 17, 135.283, 0.576923, 
  0.182524}, {"sfin", 7, 21.6667, 0.576923, 0.0263368}, {"agr", 4, 
  14., 0.454545, 0.0100853}, {"ma7", 8, 3.86667, 0.416667, 
  0.0577164}, {"ma9", 8, 6.5, 0.375, 0.149746}, {"ma10", 6, 6.5, 
  0.384615, 0.0731149}, {"srtl", 8, 17.6167, 0.483871, 
  0.0613707}, {"str1", 6, 14., 0.384615, 0.0629248}, {"sbus", 9, 43.2,
   0.483871, 0.0955785}, {"ma1", 4, 14., 0.319149, 
  0.0366005}, {"ma15", 2, 0.333333, 0.3, 0.00725712}, {"stel", 3, 0., 0.333333, 0.0766315}};

community={{"min", "scst", "ma7", "ma9", "ma10", "srtl"}, {"sfin", "str1", 
  "sbus", "ma15", "stel"}, {"segw", "ma6", "swhl"}, {"agr", "ma1"}};

This code:

Column[Table[
   {filteredData = 
     Select[centralityTable, MemberQ[community[[i]], #[[1]]] &];
    TableForm[filteredData, 
     TableHeadings -> {None, {"\nCommunity " <> ToString[i], 
        "Degree\nCentrality", "Betweenness\nCentrality", 
        "Closeness\nCentrality", "Eigenvector\nCentrality"}}]}, {i, 
    Length[community]}
   ] // Flatten]

generates:

enter image description here

My question: How can I elegantly make a single table without repetition of the column names and separating individual tables with a little empty horizontal space to differentiate individual tables from each other?

$\endgroup$

1 Answer 1

4
$\begingroup$

Unfortunately, TableForm is not very flexible. Therefore, you have to insert the spaces by hand:

space[x_] = {Prepend[Table[" ", {4}], x]};
tab = Join[centralityTable[[;; 6]], space["Community 2"], 
   centralityTable[[7 ;; 11]], space["Community 3"], 
   centralityTable[[12 ;; 14]], space["Community 4"], 
   centralityTable[[14 ;;]]];
TableForm[tab, 
 TableHeadings -> {None, {"\nCommunity 1", "Degree\nCentrality", 
    "Betweenness\nCentrality", "Closeness\nCentrality", 
    "Eigenvector\nCentrality"}}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks very much for the code. Is there a way to substitute each community as a group in "tab" above. I wanted to use Map each community as a group rather than selecting elements from a list. $\endgroup$ Feb 29 at 12:26
  • 1
    $\begingroup$ Try to make a grid or table of each group. And then insert this group as an element in a grid or table. $\endgroup$ Feb 29 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.