Suppose that I have the following
table = List[{"ID", "Variable 1", "Variable 2"}, {"Alpha", 1,
0}, {"Beta", 1, 1}, {"Alpha", 0, 0}, {"Gamma", 1, 0}, {"Gamma", 2,
2}]
Regard to this Post, we can use select
(user-defined function) to select what we want based on either rows or columns. For example, we can use
select[table, where["ID" == "Alpha"]]
the return will be {{"Alpha", 1, 0}, {"Alpha", 0, 0}}
.
If I want to select multiple categories, for example, I want "Alpha" and "Gamma", I can use
select[table, where["ID" == "Alpha"||"ID" == "Gamma"]]
My point here is that you can do this if you have small table. What if you have very large table and you need to select multiple categories. You may have to write
select[table, where["ID" == "Alpha"||"ID" == "Gamma"||"ID"=="Beta"||....so on]]
What I did was to use
Flatten[select[table, where["ID"==#]]&/@{"Alpha", "Gamma"},1]
but it is slow if you have very large table.
Could anyone give me suggestions?