After some calculations and grouping I have a Dataset
similar to the following form:
data = Dataset@<|
"A" -> Dataset@<|
"x" -> <|"c1" -> 22, "c2" -> 34|>,
"y" -> <|"c1" -> 1, "c2" -> 18|>,
"z" -> <|"c1" -> 11, "c2" -> 2|>
|>,
"B" -> Dataset@<|
"x" -> <|"c1" -> 13, "c2" -> 4|>,
"y" -> <|"c1" -> -2, "c2" -> 5|>,
"z" -> <|"c1" -> 33, "c2" -> 12|>
|>
|>
The row names are items of a groups located in another dataset with form similar to the following:
groups = Dataset@{
<|"Name" -> "Group1", "Id" -> "x"|>,
<|"Name" -> "Group1", "Id" -> "y"|>,
<|"Name" -> "Group2", "Id" -> "z"|>
}
I would like to Select
(or the equivalent) the named rows in the sub-datasets of data
that have row keys in "Group1"
of groups
. This is to be in a Manipulate
or DynamicModule
where the user will select the group name from groups
and have final calculations made and displayed from that group in data
across the rows.
I can get a list of the ids for the a group with:
Normal@groups[Select[Function[{row}, row["Name"] == "Group1"]], "Id"]
(* {"x", "y"} *)
As I understand data[All, op]
should run operator op
on the sub-dataset in each row of data
. I planned on using KeyValueMap
in a Select
for op
like so.
data[All,
Select[
KeyValueMap[
Function[{key, value},
ContainsAny[{key},
Normal@groups[Select[Function[{row}, row["Name"] == "Group1"]], "Id"]]
], #] &]
]
However, this is returning empty sub-datasets.
How do I get the following as my result? I've had a look at JoinAcross
but it doesn't seem to be for this purpose.
Dataset
are typically unnecessary $\endgroup$