Just to show that there are always a zillion ways to do things in Mathematica, here is my version. Actually, I myself would have used Flatten
and its mind-shattering second argument after having learned of its existence a couple of months ago.
Contrary to the Flatten
method this one is straightforward and easy to understand, but boorish and probably not very efficient.
I'll start with a slightly modified test table to better demonstrate the results:
t = Drop[Table[q[i, #], {i, 10}], #] & /@ Range[10]) // TableForm
The ragged array is changed to a rectangular using PadRight
, padding it with a unique symbol generated by Unique
. I then Transpose
the matrix and remove the unique symbol by replacing it with Sequence
(think of it as a black hole).
u = Unique[];
m = Length /@ t // Max;
Transpose[PadRight[#, m, u] & /@ t] /. u -> Sequence[] // TableForm
This is probably how Mr.Wizard does it:
Module[{u}, Transpose[PadRight[t, Automatic, u]] /. u -> Sequence[]]
Same result, but compacter code.