2
$\begingroup$

Consider the following list, with sublists of different lengths

list = {{{0.8, 0.8, 0.8}}, {{1, 1, 1}, {4, 1, 1}, {3, 3, 2}}, {{1.2, 
     1.2, 1.2}}, {{1.4, 1.4, 1.4}}, {{1.6, 1.6, 1.6}, {4, 2, 2}}};
Map[Length, list]; (*{1, 3, 1, 1, 2}*)
n = Max[%]; (*3*)

how can this this list be separated into n lists of the length of the original list, where the positions of the elements are maintained, i.e, the output should be

e1={{{0.8, 0.8, 0.8}}, {{1, 1, 1}}, {{1.2, 1.2, 1.2}}, {{1.4,1.4,1.4}}, {{1.6, 1.6, 1.6}}}
e2={{}, {{4, 1, 1}}, {}, {}, {{4, 2, 2}}}
e3={{}, {{3, 3, 2}}, {}, {}, {}}
$\endgroup$

1 Answer 1

5
$\begingroup$
Transpose @ PadRight[list, Automatic, {}]
{{{0.8, 0.8, 0.8}, {1, 1, 1}, {1.2, 1.2, 1.2}, {1.4, 1.4, 1.4}, {1.6, 1.6, 1.6}},
 {{}, {4, 1, 1}, {}, {}, {4, 2, 2}}, 
 {{}, {3, 3, 2}, {}, {}, {}}}
Transpose[PadRight[list, Automatic, {}]] /. p : {__?NumericQ} :> {p}
{{{{0.8, 0.8, 0.8}}, {{1, 1, 1}}, {{1.2, 1.2, 1.2}}, 
  {{1.4, 1.4, 1.4}}, {{1.6, 1.6, 1.6}}}, 
 {{}, {{4, 1, 1}}, {}, {}, {{4, 2, 2}}}, 
 {{}, {{3, 3, 2}}, {}, {}, {}}}
$\endgroup$

Your Answer

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

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