So I'm trying to make a function to compute a bunch of descriptive statistics at once. What I've got so far:

DescriptiveStats[m_] := {Mean= Mean[m], Variance= Variance[m], 
  Median= Median[m], Max= Max[m], Min= Min[m], Skew= Skewness[m], 
  Kurtosis= Kurtosis[m]}

(can't seem to get a code block working sorry...)

In each of these, I'm using a text-cell for the bit that says (for example) Mean=

However, I end up getting the following display (using some randomly generated data):

{9.86873 TextCell["Mean="], 1.86686 TextCell["Variance="], 
 9.83039 TextCell["Median="], 14.3527 TextCell["Max="], 
 6.388 TextCell["Min="], 0.150053 TextCell["Skew="], 
 2.87745 TextCell["Kurtosis="]}

Any ideas as to why I'm getting this weird display and how I can fix it?

  • $\begingroup$ Welcome! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – user9660
    Aug 10 '16 at 6:55
  • $\begingroup$ Thanks @Kuba! Definitely a duplicate, my bad, couldn't find it in my searching. And thanks for the warm welcome @Louis! $\endgroup$
    – keefles
    Aug 10 '16 at 7:16

Recommend that you use Row in definition of DescriptiveStats

DescriptiveStats[m_List] := 
 Row[{"Mean=", Mean[m], ", Variance=", Variance[m], "\nMedian=", 
   Median[m], ", Max=", Max[m], ", Min=", Min[m], "\nSkew=", 
   Skewness[m], ", Kurtosis=", Kurtosis[m]}]

data = RandomVariate[NormalDistribution[], 200];


enter image description here

  • $\begingroup$ That's done it! Thank you very much! $\endgroup$
    – keefles
    Aug 10 '16 at 7:14

Grid is the most versatile formatting function for producing tabular output. It allows almost endless twiddling with the look of the table. Here is a relatively simple example of what Grid cam do for your problem.

descriptiveStats[m_List] :=
    {{Mean, Mean[m], Median, Median[m]},
     {Min, Min[m], Max, Max[m]}, 
     {Skewness, Skewness[m], Kurtosis, Kurtosis[m]},
     {Variance, Variance[m], "", ""}},
    BaseStyle -> {"SR"},
    Dividers -> {3 -> {AbsoluteThickness[1.5], Black}},
    Alignment -> {{1 -> Left, 2 -> ".", 3 -> Left, 4 -> "."}}]

data = {1.21, 3.4, 2.15, 4, 15.5};


  • $\begingroup$ What does "SR" stand for? (Is it "StandardReport"?) Do you have a link to the properties of this BaseStyle? $\endgroup$
    – Karsten 7.
    Aug 10 '16 at 16:26
  • $\begingroup$ @Karsten7. It stands for "Sans-serif Regular". Here is a link for you to follow for more info. $\endgroup$
    – m_goldberg
    Aug 10 '16 at 16:38
  • $\begingroup$ Thanks a lot! Search couldn't find it. Also, nice Q&A I didn't see before. $\endgroup$
    – Karsten 7.
    Aug 10 '16 at 17:40

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