3
$\begingroup$

I have three data sets, each generated by Table in the following manner:

data1 = Table[f[n],{n,1,10}];
data2 = Table[g[n],{n,1,10}];
data3 = Table[h[n],{n,1,10}];

I would like to generate a nice looking table with these results in the following style:

+-----+------------+------------+------------+
|  n  |    Col1    |    Col2    |    Col3    |
+-----+------------+------------+------------+
|   1 | data1[[1]] | data2[[1]] | data3[[1]] |
|   2 | data1[[2]] | data2[[2]] | data3[[2]] |
| ... |            |            |            |
+-----+------------+------------+------------+

How can I do so, without modifying my code for generating the tables?

$\endgroup$

1 Answer 1

6
$\begingroup$
Grid[Prepend[MapIndexed[Join[#2, #1] &, Transpose[{data1, data2, data3}]],
             {"n", "Column 1", "Column 2", "Column 3"}], 
     Dividers -> {{{True}}, {True, True}}, Frame -> True]

formatted table

$\endgroup$
1
  • $\begingroup$ Wow, amazing! Thank you! $\endgroup$
    – Klangen
    Commented Mar 24, 2020 at 14:50

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.