4
$\begingroup$

I would like to plot a histogram for multiple datasets in a dataset query, but can't quite seem to make it work in operator notation:

titanic = ExampleData[{"Dataset", "Titanic"}];
titanic = Dataset@Flatten@Table[
     Map[Append[#, "score" -> RandomReal[100]] &, Normal@titanic], 
     20];

(*this ugly version works:*)
Histogram @ Transpose[List @@@ titanic[Slice[All, {"age", "score"}]] // Normal]

(*but the operator forms version does not:*)
titanic[Histogram, Slice[All, {"age", "score"}]]
titanic[Slice[All, {"age", "score"}] /* Histogram]

enter image description here

How to do this with just operator forms?

$\endgroup$
  • $\begingroup$ What is the Slice function? $\endgroup$ – Edmund Sep 12 '18 at 2:24
  • $\begingroup$ It's in GeneralUtilities $\endgroup$ – M.R. Sep 12 '18 at 2:31
  • $\begingroup$ Also note that Transpose@ titanic[Transpose /* Query[<|#, "score" -> RandomReal[{0, 100}, 1309]|> &]] is a more efficient addition of "score". $\endgroup$ – Edmund Sep 12 '18 at 2:35
  • $\begingroup$ closely related: How to pass options to ListPlot when using a DataSet? $\endgroup$ – kglr Sep 12 '18 at 2:36
3
$\begingroup$

You may use Composition with Transpose.

titanic[Histogram@*Transpose, {"age", "score"}]

Mathematica graphics

Hope this helps.

$\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.