# A summary command for statistics

In R I can do:

summary(data)


Which gives the min, max, median, first, and third quartiles. Is there a similar single command in Mathematica for this?

I know I can do:

data = RandomInteger[{0, 100}, 100]
Table[f[data], {f, {Min, Quantile[#, .25] &, Median,
Quantile[#, .75] &, Max}}]


But wondering if there is a single command for this.

• No, there isn't. – Stefan R Sep 11 '15 at 21:42
• @StefanR - Actually, since Quantile accepts a list of quantiles: Quantile[data, Range[0, 1, .25]] – Bob Hanlon Sep 11 '15 at 22:46

Even if there wasn't one, there is one now: I think you've just written it yourself :-)

summary[dset_] := Through[{Min, Quantile[#, .25] &, Median, Quantile[#, .75] &, Max}[dset]]

SeedRandom[1234]
data = RandomInteger[{0, 100}, 100];
summary[data]

(* Out: {0, 18, 91/2, 66, 98} *)

• Addendum: there might be a situation where one might need to fiddle with the third argument of Quantile[]. See e.g. this. – J. M. will be back soon Oct 7 '15 at 11:49
• @J.M. ah! Interesting, thank you for pointing it out. I'm delighted to see that you're back! – MarcoB Oct 7 '15 at 12:28

On 2019-10-02 the resource function "RecordsSummary" was published at the Wolfram Function Repository.

Here is usage example (from the resource function page):

Block[{n = 200},
arr = Flatten /@
Transpose[{RandomReal[{-10, 10}, {n, 2}],
MapAt[ToLowerCase,
RandomChoice[CharacterRange["A", "Z"], {n, 2}], {All, 2}],
RandomChoice[{E, I, \[CapitalGamma]}, n]}]];

ResourceFunction["RecordsSummary"][arr]


Some time ago I programmed such a function, RecordsSummary, inspired by R's summary. Here is an example of its usage: Census data summary .

As the name implies, it is assumed that we have a list of records, all with the same length, and we want the columns to be summarized. (Each record is a row.)

You can get the package MathematicaForPredictionUtilities.m from MathematicaForPrediction at GitHub or simply run this command:

Import["https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/MathematicaForPredictionUtilities.m"]


Let us create random data.

data = RandomInteger[{0, 100}, 100];
dataCat = RandomChoice[Characters["azbuka"], 100];
data2 = RandomInteger[{0, 100}, {100, 4}];


Here are examples of using RecordsSummary over the created data.

1. Call on a 1D array:

RecordsSummary[ data ]


2. Summary of a 2D numeric array. The columns are named automatically.

RecordsSummary[N[data2]]


3. Fancy output of numerical and categorical data summary. The column names are the second argument given to RecordsSummary.

Grid[{RecordsSummary[
Transpose[{N[data], dataCat}], {"Numeric", "Categorical"}]},
Alignment -> Top, Dividers -> All]


• Can we have Recordsummary with respective to two variables that is, a response variable that is categorical and a predictor variable that is numeric? – Srajan Dec 1 at 23:07
• @Srajan I am not sure what do you meant. The answer is "yes" to both interpretations I can come up with. 1. If you have two columns, a categorical and a numerical one, then see the last example in this answer. 2. If you mean an association of number-symbol pairs, then you can use ResourceFunction["RecordsSummary"][asc, Thread -> True]. – Anton Antonov Dec 2 at 12:00