Let's say I have a Dataset consisting of nested Associations (in this case, created through a Query) and I want to convert the first set of Keys into Values. Is there a way to do this without having to drop the Keys, create a new column, and then Join the two together?
Consider the following example where I take the Mean age by sex and class of the passengers in the Titanic ExampleData:
data=ExampleData[{"Dataset", "Titanic"}][GroupBy["class"],
GroupBy["sex"] /* KeySort, Mean, #age &]
Here is what I am looking for:
And I can get it with this code:
final = Join[AssociationThread["class" -> #] & /@ Keys[data],
Values[data], 2]
However, the solution seems like it may take more steps than required. Is there a simpler / more elegant code that I am neglecting?


ungroupfunction from that Q/A answer, isdata[ungroup[{"class"}]]. – Leonid Shifrin Nov 05 '19 at 14:46ungroupmight look more complex than your code, but it addresses a general problem, of which yours is a special case. So I would still consider this a duplicate of that. The fact that hereDatasetis used and there isn't, matters very little I think. – Leonid Shifrin Nov 05 '19 at 15:13Dataset,KeyandValue. Ultimately, I was looking for a simpler approach and in this case,ungroupisn't that. I do agree that your approach is more universal. Have you considered submitting to the function repository so it would in fact be a simple solution for a variety of situations? – kickert Nov 05 '19 at 15:20