Are table headings for aesthetics only?

For example, if I have:

table1 = TableForm[{{1, 1, 0, 0, 0}, {0, 1, 0, 0, 0}, {0, 0, 1, 0, 0},
{0, 0, 1, 1, 1}, {0, 0, 1, 0, 1}, {1, 1, 0, 0, 0},
{0, 1, 1, 0, 0}},
TableHeadings -> {{"1", "2", "3", "4", "5", "6", "7"},
{"a", "b", "c", "d", "e"}}]


is there any way to refer to a part of the table by the heading names?

For example, if I want the position of all 1's in the table,

Position[table1, 1]


I would like this to return both numbers and letters. Is this possible?

-
What wasn't really spelled out by the answers, but is important to understand, is that the purpose of TableForm is displaying tables in a pretty way. Don't use TableForm as a data structure (unless you know for certain that this is an advantage for you...). Just use it to display a table stored as a List in two-dimensional (readable) form. – Szabolcs Nov 26 '12 at 20:33

Let's figure it out by inspecting the full form of a TableForm:

TableForm[{{1, 2}, {3, 1}}, TableHeadings -> {{"a", "b"}, {"c", "d"}}] // FullForm


Evidently, then, we can obtain the list as the first element of the TableForm and we can find the headings, assuming they exist, from the TableHeadings rule. Under these assumptions, one solution is to create a parallel table of the desired addresses of all list positions and index into that:

addresses = Outer[List, Sequence @@ (TableHeadings /. Cases[table1, _Rule]), 1];
addresses[[Sequence @@ #]] & /@ Position[table1 // First, 1]


{{1,a},{1,b},{2,b},{3,c},{4,c},{4,d},{4,e},{5,c},{5,e},{6,a},{6,b},{7,b},{7,c}}

-
Thank you @whuber! I am still very new at this and I didn't know one could use //Fullform inspect functions. – Pancholp Nov 27 '12 at 0:00

Here is an alternative formulation that does the same thing as the answer by @whuber but uses what I think is more idiomatic syntax:

Flatten[Pick[
],
table1[[1]],
1],
1]

{{"1", "a"}, {"1", "b"}, {"2", "b"}, {"3", "c"}, {"4", "c"}, {"4",
"d"}, {"4", "e"}, {"5", "c"}, {"5", "e"}, {"6", "a"}, {"6",
"b"}, {"7", "b"}, {"7", "c"}}


The table headings are options, so they (like all options) can be extracted using OptionValue[Options[table1], TableHeadings]. I then construct a matrix of tuples with the combined table headings, similar to what @whuber did (using Outer). The command Pick does the remaining work.

-
I had never seen these functions either. I will read up on Options too. Thanks @Jens, I really appreciate it! – Pancholp Nov 27 '12 at 0:03

To emphasize Szabolcs' point, if you had data you wanted to display and work with, you might put and row and column identifiers in separate lists

rowNames = {"1", "2", "3", "4", "5", "6", "7"};
columnNames = {"a", "b", "c", "d", "e"};
data = {{1, 1, 0, 0, 0}, {0, 1, 0, 0, 0}, {0, 0, 1, 0, 0}, {0, 0, 1,1, 1}, {0, 0, 1, 0, 1}, {1, 1, 0, 0, 0}, {0, 1, 1, 0, 0}};


and use TableForm[ ] to display it in a table:

TableForm[data, TableHeadings -> {rowNames, columnNames}]


But, to get an element from data, you would probably use some function like this:

getdata[row_, col_] := Module[{r, c},
r = Position[rowNames, row][[1, 1]];
c = Position[columnNames, col][[1, 1]];
data[[r, c]]
]


in the following manner:

getdata["2", "b"]


to get the returned value of 1. So, the table display created by TableForm[ ] is just for display and not a normal way to store data.

-
data = {{1, 1, 0, 0, 0}, {0, 1, 0, 0, 0}, {0, 0, 1, 0, 0}, {0, 0, 1, 1,
1}, {0, 0, 1, 0, 1}, {1, 1, 0, 0, 0}, {0, 1, 1, 0, 0}};

rowHdrs = {"1", "2", "3", "4", "5", "6", "7"};

colHdrs = {"a", "b", "c", "d", "e"};


Using version 10 capabilities of Association and Dataset

\$Version

(* "10.2.0 for Mac OS X x86 (64-bit) (July 7, 2015)" *)



keys = Position[dataset, 1] /. Key[x_] :> x

(* {{"1", "a"}, {"1", "b"}, {"2", "b"}, {"3", "c"}, {"4", "c"}, {"4", "d"}, {"4",
"e"}, {"5", "c"}, {"5", "e"}, {"6", "a"}, {"6", "b"}, {"7", "b"}, {"7",
"c"}} *)


Verifying that all the values are one

dataset @@@ keys

(* {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} *)

-