1

The following question is related to: Elementwise join

I have the following code:

listStrings = {"LCM[48,108]", "LCM[450,780]", "LCM[49,66,33]", 
  "LCM[10,15,18 ]", "LCM[8,16,25]", "LCM[32,45,50]", "LCM[125,325]", 
  "LCM[258,645]"};

listData = {LCM[48, 108], LCM[450, 780], LCM[49, 66, 33], 
   LCM[10, 15, 18], LCM[8, 16, 25], LCM[32, 45, 50], LCM[125, 325], 
   LCM[258, 645]};

primeFactors = FactorInteger[listData];

As output I would like to have such a table:

enter image description here

From Elementwise join I could reproduce with:

Grid[MapThread[Riffle[{#1}, {#2}] &, {listData, primeFactors}], 
 Frame -> All, Alignment -> Left]

the last two columuns:

enter image description here

How can I join to this the first column (listStrings) at left as shown in the table above?

Is it possible to generalize the code for any number of columns (lists)?

mrz
  • 11,686
  • 2
  • 25
  • 81

2 Answers2

4
Grid[Transpose[{listStrings, listData, primeFactors}], 
  Frame -> All, Alignment -> Left]

grid

seems to work.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
  • so simple ... I am using Transpose always to plot 2d data with ListPlot ... here I was blind ... thanks – mrz Nov 16 '15 at 22:27
2
list =
 {"LCM[48,108]", "LCM[450,780]", "LCM[49,66,33]", 
  "LCM[10,15,18]", "LCM[8,16,25]", "LCM[32,45,50]", "LCM[125,325]", 
  "LCM[258,645]"};

Grid[
 Join[
  {{"LCM", "Result", "FactorInteger"}},
  Transpose[{list, #, FactorInteger@#}] &[ToExpression@list]
  ],
 Alignment -> {{Left, Right, Left}},
 Background -> {None, {LightGray}},
 Dividers -> All,
 Spacings -> {1, 1}]

enter image description here

eldo
  • 67,911
  • 5
  • 60
  • 168