Memra

Min · 1st Qu. · Median · Mean · 3rd Qu. · Max · NA's

◈ 9 cards

summary(orders$amount) prints Min 90.0, 1st Qu. 241.2, Median 445.0, Mean 511.7, 3rd Qu. 670.0, Max 1320.0 — four significant digits. A chr column shows only Length/Class/Mode; make it a factor for counts. sd() is 362.8193; quantile(x, c(0.25, 0.75)) is 241.25 and 670. The NA's column appears only when there are some.

Six numbers per column, in one call

Module 4 built Maple & Birch's descriptive statistics one formula at a time — AVERAGE, MEDIAN, QUARTILE.INC, MIN, MAX — and Excel's ToolPak printed them as a block. summary() is that block, for every column at once:

> summary(orders$amount)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   90.0   241.2   445.0   511.7   670.0  1320.0 

Six statistics, always in this order: minimum, first quartile, median, mean, third quartile, maximum. Two things to notice. 1st Qu. is the 25th percentile — the same type = 7 interpolation as Sheets' QUARTILE.INC(D2:D13, 1), which gave 241.25 in Module 4. And summary() prints four significant digits: 241.25 shows as 241.2 and the mean 511.6667 as 511.7. The full values come from the individual functions:

> mean(orders$amount)
[1] 511.6667
> median(orders$amount)
[1] 445
> sd(orders$amount)
[1] 362.8193
> quantile(orders$amount, c(0.25, 0.75))
   25%    75% 
241.25 670.00 
> IQR(orders$amount)
[1] 428.75

sd() is the sample standard deviation (n − 1) — STDEV.S, never STDEV.P. quantile() prints a named vector: the names are the percentiles asked for.

Worked example — the whole frame

> summary(orders)
    order_id        prov             channel              amount      
 Min.   :1001   Length:12          Length:12          Min.   :  90.0  
 1st Qu.:1004   Class :character   Class :character   1st Qu.: 241.2  
 Median :1006   Mode  :character   Mode  :character   Median : 445.0  
 Mean   :1006                                         Mean   : 511.7  
 3rd Qu.:1009                                         3rd Qu.: 670.0  
 Max.   :1012                                         Max.   :1320.0  
     units        order_date       
 Min.   :1.000   Length:12         
 1st Qu.:2.000   Class :character  
 Median :3.000   Mode  :character  
 Mean   :3.417                     
 3rd Qu.:4.250                     
 Max.   :8.000                     

Three lessons in one print. A character column (prov, channel, order_date) gets only Length, Class, Mode — a count of cells and the type, no statistics, because text has none. Convert it to a factor and the same call counts the categories:

> summary(factor(orders$prov))
AB BC ON QC 
 2  3  4  3 

And order_id gets a mean of 1006 — arithmetically true, analytically meaningless. An identifier is nominal (Module 2) whatever its type; summary() does not know that. You do.

The column that appears only when needed

With one amount missing:

> summary(x)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
   90.0   232.5   420.0   489.1   575.0  1320.0       1 

A seventh column, NA's, with the count. It is absent when the count is zero — so its presence is itself the check. The other six are computed on the 11 present values, which is why the mean moved from 511.7 to 489.1.

Type the two calls, then read the block

The worksheet reads three values off the printed summary(orders$amount) at the precision R printed them.

CRISP-DM: summary() is data understanding → describe data — the ToolPak block, for every column, in one line.

Min.1st Qu.MedianMean3rd Qu.Max.90.0241.2445.0511.7670.01320.0An NA's column is added on the right only when the column has missing values.
summary(orders$amount), as printed. Always this order; four significant digits, so 241.25 shows as 241.2 and the mean 511.6667 as 511.7.
NORMAL ~/memra/learn/afm-112/summary-of-a-data-frame utf-8 LF