I have a function of this form


that gives me a list as an output,where the first column collects names of output variables.
Is it possible to customize TableForm so that when I evaluate:


it takes that first column and displays it as a column table heading, and the rest columns as data?
I don't want to make another function for this because I want to make it as simple as possible. The function should look something like this:

    TableForm[ Garch[a_, b_, c_, ___]] := 
      TableForm[ Garch[a, b, c][[All, 2 ;; -1]],
        TableHeadings -> {ToString /@ Garch[a, b, c][[All, 1]], None}]

So,I'll try to be more precise.The reason I don't want to define a new function is because in the end I want to create a compact mathematica package(this is part of my master thesis) that other students would use without learning another function. If you are familiar with RLink and the mathematica representation of data.frame object you'll understand what I mean.For example evaluate the next code:


Now when we do


we should get the table with row names 1,2,3 and column names a,b.So I'm guessing that TableForm is somehow modified to recognize the functions in first output and show them like in the second case. Analogically to this I would like to modify the TableForm function to recognize my Garch function and do the operations you suggested.


1 Answer 1


I am not certain about what you are asking, so this may be off target. My understanding is your Garch function returns a list like this one;

test = {{a, 91, 48, 30, 50}, {b, 49, 81, 18, 74}, {c, 30, 23, 98, 96}};

If that is right, then defining a function

garchForm[g_List] := 
  TableForm[g[[All, 2 ;; -1]], TableHeadings -> {ToString /@ g[[All, 1]], None}]

will give the following result:

test // garchForm


I think this the easiest to do what I think you are looking for. I further note that you might not need to map ToString over the row labels. TableForm doesn't require labels to be strings.

However, because you say you don't want to define a new function (although it escapes me why a new function is bad), I also note you can always use a pure function:

test // TableForm[#[[All, 2 ;; -1]], TableHeadings -> {ToString /@ #[[All, 1]], None}] &
  • $\begingroup$ Thanks for responding,I edited my question,hope is now clear what I want to do,basically you understood it correctly,now it's just the problem of finding the solution. $\endgroup$ Apr 3, 2014 at 1:16

Your Answer

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

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