Mathematica newbie here, thanks for your patience. I have a list of 2-element lists, i.e.
{{x1,y1}, {x2,y2}, ... {xn,yn}}
But I want to rearrange them so that they are two lists of N elements, i.e.
{{x1,x2, ... xn},{y1,y2, ... yn}}
I'm sure this is child's play for most of you, but it's really giving me trouble. I found another page that I thought would be a solution: Pretty way to group elements at odd and even positions
The answers there take a flat list {x1,y1,x2,y2, ... xn,yn} and produce the output that I want. But I need to flatten my list first. But when I call Flatten inside of one of those functions it doesn't work. The authors of the solutions have used MMA magic which I do not yet comprehend. So here are some examples of my modifications of the solutions from the page linked above which do not work:
unzip[listoftuples_] :=
Take[Flatten[listoftuples], {#, -1, 2}] & /@ {1, 2}
unzip[listoftuples_] :=
Flatten[listoftuples][[# ;; ;; 2]] & /@ {1, 2}
unzip[listoftuples_] :=
Downsample[Flatten[listoftuples], 2, #] & /@ {1, 2}
Yet if I remove Flatten[] from any of those solutions and instead call Flatten[] outside of that function, i.e. unzip[Flatten[data]] then it works. MMA is obviously powerful and flexible, but really confusing and cryptic to newcomers.
Transpose. – CA Trevillian Jul 22 '22 at 22:16{}button above the edit window. The edit window help button?is useful for learning how to format your questions and answers. You may also find the meta Q&A, How to copy code from Mathematica so it looks good on this site, helpful – Michael E2 Jul 22 '22 at 23:08ClearAll[unzip]to be sure you are starting over. Symbols in Mma are allowed to have multiple definitions. It something that new users don't always appreciate (e.g. that a typo persists and causes a bug). – Michael E2 Jul 22 '22 at 23:14