In this previous post (Data Table Manipulation in Mathematica) we find the brilliant suggestion proposed by Leonid Shifrin that allows to select specific rows identified by the header name.
I'm now looking for a way to then also select the data of a specific column (or more columns) of the subset of data generated by Leonid's select function.
Suppose we have this data:
table = List[
{"ID", "Variable 1", "Variable 2"},
{"Alpha", 1, 0},
{"Beta", 1, 1},
{"Alpha", 0, 0}]
which when formatted as a grid looks like this:
ID Variable 1 Variable 2
Alpha 1 0
Beta 1 1
Alpha 0 0
Using Leonid's function we can obtain this:
subset = select[table, where["Variable 1" == 1]]
(* {{"Alpha", 1, 0}, {"Beta", 1, 1}} *)
Suppose that we now want to sum all the values that are in the column named 'Variable 2'. We could just do this:
Total[subset[[All,3]]]
However, in this way we loose the advantage of using Leonid's function that can work directly with header names. Ideally, I would like to find a way to get those data by using the header name. Something like:
Total[subset[[All,"Variable 2"]]]
or, even better:
select[table, where["Variable 1" == 1], columns["Variable 2"]]
Any hints would be highly appreciated.