Here is a slight modificaiton of Mathematica's example dataset from the documentation:
ds = Dataset[{
<|"a" -> 1, "b" -> "x", "team" -> {"John"}|>,
<|"a" -> 2, "b" -> "y", "team" -> {"Mary", "Alice"}|>,
<|"a" -> 3, "b" -> "z", "team" -> {"Alice"}|>,
<|"a" -> 4, "b" -> "x", "team" -> {"Lucas", "Charlie"}|>,
<|"a" -> 5, "b" -> "y", "team" -> {"Charlie", "Bobby", "Ana"}|>,
<|"a" -> 6, "b" -> "z", "team" -> {}|>}]
Grouping by columns "a" or "b" is easy. But how could I group by column "team" (taking into account, of course, the different entries)?
I think of this as e.g. a dataset containing active projects within a company, and "team" is the list of people involved. What I want to do then is to group the projects by the people involved.
The way I found to do this is as
staff = {"John","Mary", "Alice","Lucas", "Charlie", "Bobby", "Ana"};
Dataset[Association[Table[person -> ds[Select[MemberQ[#team, person] &]], {person,
staff}]]]
But it doesn't look great. And I am not convinced this is the proper way of handling this type of query. This seems like a standard problem and there should be a proper way of dealing with it. But I can't seem to find out.
Any help is appreciated!