TransWikia.com

Add calculation name on dataset statistics

Mathematica Asked on October 22, 2021

I am working on, with the Animal Weights data set and creating MyFunctionwhich calculates the Max,Min,Mean,Median and first quartile. Then a apply the function to the data set and show it as a menu with MenuView. My question is, is there a possible way to use add the calculation name in the data set object? Like in the image below.

 ResourceObject["Sample Data: Animal Weights"];
dataset = ResourceData["Sample Data: Animal Weights"];

MyFunction[dataset_] :=
 {Max[dataset], Min[dataset], Mean[dataset], Median[dataset], 
  Quantile[dataset, 0.25]}

MenuView[{"BodyWeight" -> dataset[MyFunction, "BodyWeight"], 
  "BrainWeight" -> dataset[MyFunction, "BrainWeight"]}]

img 1

One Answer

Clear["Global`*"]

ResourceObject["Sample Data: Animal Weights"];
dataset = ResourceData["Sample Data: Animal Weights"];

MyFunction[
  dataset_] := {# /. _Function :> "1st Quartile", #[dataset]} & /@ 
     {Max, Min, Mean, Median, Quantile[#, 0.25] &}

MenuView[{"BodyWeight" -> dataset[MyFunction, "BodyWeight"], 
  "BrainWeight" -> dataset[MyFunction, "BrainWeight"]}]

enter image description here

Answered by Bob Hanlon on October 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP