Why summary () gives a different maximum max ()

using R-2.15.2 on Windows XP, I get a different maximum from summary() than from max() . Why is this so?

Here is the relevant code:

 > class(dat) [1] "data.frame" > dim(dat) [1] 3850 54 > summary(dat$enrol) Min. 1st Qu. Median Mean 3rd Qu. Max. 26 945 1744 3044 3128 183200 > max(dat$enrol) [1] 183151 

Any ideas why summary() rounds the result to?

Best oliver

+6
source share
1 answer

How the results are printed for the digits argument. Defaults to

 > max(3, getOption("digits")-3) [1] 4 

Why R rounds up are just the default rules - go to the nearest even digit. We can see this in action with signif() :

 > signif(183151, digits = 4) [1] 183200 

which, as ?summary tells us, is that summary() and controlled by the digits argument:

 digits: integer, used for number formatting with 'signif()' (for 'summary.default') or 'format()' (for 'summary.data.frame'). 

For more information on rounding, read ?signif .

To get more meaningful numbers, pass a larger number of summary() using the digits argument.

for instance

 > set.seed(1) > vec <- c(10, 100, 1e4, 1e5, 1e6) + runif(5) > summary(vec) Min. 1st Qu. Median Mean 3rd Qu. Max. 10.3 100.4 10000.0 222000.0 100000.0 1000000.0 > summary(vec, digits = 7) Min. 1st Qu. Median Mean 3rd Qu. Max. 10.3 100.4 10000.6 222022.5 100000.9 1000000.0 > summary(vec, digits = 8) Min. 1st Qu. Median Mean 3rd Qu. Max. 10.3 100.4 10000.6 222022.5 100000.9 1000000.2 
+15
source

All Articles