# Text and maths displaying weirdly [duplicate]

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?

• 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! – user9660 Aug 10 '16 at 6:55
• Thanks @Kuba! Definitely a duplicate, my bad, couldn't find it in my searching. And thanks for the warm welcome @Louis! – 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];

DescriptiveStats[data]


• That's done it! Thank you very much! – 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] :=
Grid[
{{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};
descriptiveStats[data]


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