I have a 2-dim array. The first 3 rows have column headings. The heading can be a single word, or 2 words (which take 2 rows) or 3 words (which take 3 rows). For each column I know which row has the most meaningful name for that column. I can't figure out how to map this and get what I want. For example:

I want my three headings to be "Year", "Amount", "Class", this is based on a2. I assume I can use Part to do this, and use Map with a LevelSpec. But I can't figure out how to make this work. Maybe I'm thinking in the wrong direction.

I suppose you need to add a1[[;;3]] since this is only part of bigger matrix.
–
KubaJun 18 '14 at 21:31

@Kuba Sorry, what's the full input supposed to be then?
–
Mr.Wizard♦Jun 18 '14 at 21:33

I just think a1 contains not only the headers but all the data. But I'm not sure. "The first 3 rows have column headings". So with the [[;;3]] it should work.
–
KubaJun 18 '14 at 21:35

@Kuba - my real data has 20+ columns and a few hundred rows. That would be a1. a2 would have the same number of columns as a1. Sorry I just tried to simplify my example. And actually to make things worse, my real a1 has an additional first dimension. However adjusting for that first dimension, user15996's solution and both of Mr. Wizard's solutions work perfectly. As usual it will still take me a little time to understand Mr. Wizard's frighteningly elegant code.
–
Mitchell KaplanJun 18 '14 at 21:46

1

Thanks for the help and the offer, but it's more helpful for me to figure it out. If I get really stuck I'll take you up on your offer.
–
Mitchell KaplanJun 18 '14 at 21:49

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.