Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6254619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:12:41+00:00 2026-05-24T14:12:41+00:00

How do I use Mathematica’s Gather/Collect/Transpose functions to convert: { { {1, foo1}, {2,

  • 0

How do I use Mathematica’s Gather/Collect/Transpose functions to convert:

{ { {1, foo1}, {2, foo2}, {3, foo3} }, { {1, bar1}, {2, bar2}, {3, bar3} } } 

to

{ {1, foo1, bar1}, {2, foo2, bar2}, {3, foo3, bar3} } 

EDIT: Thanks! I was hoping there was a simple way, but I guess not!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T14:12:41+00:00Added an answer on May 24, 2026 at 2:12 pm

    Here is your list:

    tst = {{{1, foo1}, {2, foo2}, {3, foo3}}, {{1, bar1}, {2, bar2}, {3,  bar3}}}
    

    Here is one way:

    In[84]:= 
    Flatten/@Transpose[{#[[All,1,1]],#[[All,All,2]]}]&@
      GatherBy[Flatten[tst,1],First]
    
    Out[84]= {{1,foo1,bar1},{2,foo2,bar2},{3,foo3,bar3}}
    

    EDIT

    Here is a completely different version, just for fun:

    In[106]:= 
    With[{flat = Flatten[tst,1]},
       With[{rules = Dispatch[Rule@@@flat]},
           Map[{#}~Join~ReplaceList[#,rules]&,DeleteDuplicates[flat[[All,1]]]]]]
    
    Out[106]= {{1,foo1,bar1},{2,foo2,bar2},{3,foo3,bar3}}
    

    EDIT 2

    And here is yet another way, using linked lists and inner function to accumulate the results:

    In[113]:= 
    Module[{f},f[x_]:={x};
      Apply[(f[#1] = {f[#1],#2})&,tst,{2}];
      Flatten/@Most[DownValues[f]][[All,2]]]
    
    Out[113]= {{1,foo1,bar1},{2,foo2,bar2},{3,foo3,bar3}}
    

    EDIT 3

    Ok, for those who consider all of the above too complicated, here is a really simple rule – based solution:

    In[149]:= 
    GatherBy[Flatten[tst, 1], First] /. els : {{n_, _} ..} :> {n}~Join~els[[All, 2]]
    
    Out[149]= {{1, foo1, bar1}, {2, foo2, bar2}, {3, foo3, bar3}}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In many symbolic math systems, such as Matlab or Mathematica, you can use a
I want to use mathematica to analyze some data of sqlite? But i don't
I'm trying to use Mathematica's NDSolve[] to compute a geodesic along a sphere using
In Mathematica, do I have to use an explicit loop to calculate the product
I'm very new to Mathematica. I want to use it as a data source
Is it possible to use Mathematica's computing capabilities from other languages? I need to
Problem description: Mathematica use \:nnnn as the syntax for unicode input. E.g., if we
I use Mathematica with JLink for a research project, which involves a lot of
I want to implement this in Mathematica: I realize I can use ParametricPlot to
Possible Duplicate: Performance difference between functions and pattern matching in Mathematica I often find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.