0
$\begingroup$

I have a row of values that I partition into a table.

row = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
rowPartitioned = Partition[row, 6]

{{1, 2, 3, 4, 5, 6}, {7, 8, 9, 10, 11, 12}}

Now I want to partition again to get the result

{{1, 2}, {7, 8}, {3, 4}, {9, 10}, {5, 6}, {11, 12}}

How could I do the second partitioning?

Another example :

Starting with the 210 value row, with values 1 to 210, the output nested table would have 6 columns and 35 rows:
(1-6) (31-36) (61-66) (91-96) (121-126) (151-156) (181-186) (7-12) (37-42) (67-72) (97-102) (127-132) (157-162) (187-192) (13-18) (43-48) (73-78) (103-108) (133-138) (163-168) (193-198) (19-24) (49-54) (79-84) (109-114) (139-144) (169-174) (199-204) (25-30) (55-60) (85-90) (115-120) (145-150) (175-180) (205-210)

$\endgroup$
  • $\begingroup$ Partition[row, 2][[Riffle[Range[1, 3], Range[4, 6]]]]? $\endgroup$ – Henrik Schumacher Jan 15 at 22:16
  • $\begingroup$ The first partition increased the depth while the second didn't, what is the rule? Please do not delete question if you want to edit it. $\endgroup$ – Kuba Jan 15 at 22:19
1
$\begingroup$

Does this provide what you're looking for?

matrix = Flatten[Transpose[Partition[#, 6] & /@ Partition[Range[210], 30]], 1]

If you want it to display as a table, you can use:

matrix//MatrixForm

The first row matrix[[1]] gives {1,2,3,4,5,6}, the second matrix[[2]] gives {31,32,33,34,35,36}, and the first column matrix[[All, 1]] gives {1,31,61,91,121,151,181,7,37,67,97,127,157,187,13,43,73,103,133,163,193,19,49,79,109,139,169,199,25,55,85,115,145,175,205}.

$\endgroup$
  • $\begingroup$ Thanks, that works great! $\endgroup$ – Jamie M Jan 16 at 7:26
  • $\begingroup$ @JamieM No problem, I'm glad it works! $\endgroup$ – MassDefect Jan 16 at 16:09
  • $\begingroup$ If the resultant matrix has row1: XXYY, row2: AABB, row3: WWEE, row4: TTGG, how could that be further nested to give row1: XX, row2: AA, row3: WW, row4: TT, row5: YY, row6: BB, row7: EE, row8: GG. $\endgroup$ – Jamie M Jan 23 at 8:30
  • $\begingroup$ @JamieM The first things that come to mind are Join[mat[[All, 1;;2]], mat[[All, 3;;4]]] or Flatten[Transpose[Partition[#, 2]&/@mat], 1] where mat is just your values above. $\endgroup$ – MassDefect Jan 23 at 8:52
  • $\begingroup$ Thanks, creating 5-nested (or more) tables now with that. $\endgroup$ – Jamie M Jan 23 at 14:34
1
$\begingroup$
Riffle @@ (Partition[#, 2] & /@ rowPartitioned)

which gives output:

{{1, 2}, {7, 8}, {3, 4}, {9, 10}, {5, 6}, {11, 12}}

Is that what you mean?

$\endgroup$
  • $\begingroup$ Hi, yes. I am trying to get a general solution for larger rows, for example, the row of values 1 to 210 (210 values). First partitioning that into 7 equal parts (1 to 30),(31 to 60),..(181 to 210). Then partition each of those 30 value rows into 5 equal parts, each 6 columns by 5 rows, and join all the data so the final nested table result would have 6 columns and 35 rows. The final nested table first column values are: 1,31,61,91,121,151,181,7,37,67,97,127,157,187,13,43,73,103,133,163,193,19,49,79,109,139,169,199,25,55,85,115,145,175,205. $\endgroup$ – Jamie M Jan 15 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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