2
$\begingroup$

Suppose I have a dataset

titanic = Uncompress[FromCharacterCode[
   Flatten[ImageData[Import["http://i.stack.imgur.com/sd05e.png"],"Byte"]]]]

Mathematica graphics

This two Groupy will give a output like

titanic[GroupBy["class"], GroupBy["sex"]]

Mathematica graphics

But actually I'd like a format like

How to get a Dateset with such structure?

$\endgroup$
  • 2
    $\begingroup$ What do you expect to be in the empty cells? Also, the result of the first GroupBy does give you result["1st", "female", "age"] for all ages of that class and gender. $\endgroup$ – Edmund Jul 1 '17 at 21:36
  • $\begingroup$ What code did you use to make the last image? And why doesn't that code satisfy you? $\endgroup$ – m_goldberg Jul 1 '17 at 21:40
  • $\begingroup$ @Edmund It keep empty still $\endgroup$ – yode Jul 1 '17 at 21:42
  • $\begingroup$ Should be result["1st", "female", All, "age"] $\endgroup$ – Edmund Jul 1 '17 at 21:42
  • $\begingroup$ @m_goldberg I have updated the structrue what I'm after. :) $\endgroup$ – yode Jul 1 '17 at 21:45
5
$\begingroup$

AFAIK, there are only two ways to present the dataset under grouping by class and sex. They are these.

Class dominant

grped1 = titanic[GroupBy["class"], GroupBy["sex"]];
new1 = Map[KeyDrop[#, {"sex", "class"}] &, grped1 // Normal, {3}];
ds1 = Dataset[new1]

ds1

Sex dominant

grped2 = titanic[GroupBy["sex"], GroupBy["class"]];
new2 = Map[KeyDrop[#, {"sex", "class"}] &, (grped2 // Normal), {3}];
ds2 = Dataset[new2]

ds2

I do not know why Mathematica formats the 1st case differently from the 2nd case, and I do not know any way to make it format the 1st case like the 2nd case.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.