0
$\begingroup$

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

$\endgroup$

1 Answer 1

1
$\begingroup$
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

$\endgroup$
4
  • $\begingroup$ Thanks, it worked. $\endgroup$
    – Las Des
    Commented Jul 20, 2020 at 20:08
  • $\begingroup$ I don´t understand why the set delayed and the _Function? $\endgroup$
    – Las Des
    Commented Jul 20, 2020 at 22:24
  • $\begingroup$ Look at {Max, Min, Mean, Median, Quantile[#, 0.25] &} // FullForm The last element needs to be handled differently. $\endgroup$
    – Bob Hanlon
    Commented Jul 20, 2020 at 23:07
  • $\begingroup$ Oh , I see now. $\endgroup$
    – Las Des
    Commented Jul 21, 2020 at 0:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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