1

If I run the following code, I get unexpected results. I don't understand why summary() results do not agree with min(), max() and other functions. There are no missing data.

Any help would be appreciated.

years <- c(2005, 2006, 
            rep(2007,  9), rep(2008,  9), rep(2010, 17), rep(2011, 14), 
            rep(2012, 16), rep(2013, 12), rep(2014,  6), rep(2015, 6))


base::summary(years)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   2000    2010    2010    2010    2010    2020 

quantile(years)
  0%  25%  50%  75% 100% 
2005 2010 2011 2013 2015 

min(years)
[1] 2005

max(years)
[1] 2015

median(years)
[1] 2011


sessionInfo()
R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

1 Answers1

4

My guess is that you have options("digits") set to something small (i.e. less than the default value of 7). Because summary() uses digits = max(3, getOption("digits")-3), rounding of the outputs is a very common cause of confusion about summary() ... if I try this with default options("digits") I can't reproduce, but I can if ...

options(digits=6)
base::summary(years)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   2000    2010    2010    2010    2010    2020 
min(years)
## [1] 2005
Community
  • 1
  • 1
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • What's the reasoning behind rounding to 3 less digits than specified in the options? – Señor O Aug 05 '15 at 15:37
  • my uninformed guess: it *might* be useful to see less detail in a "summary" of the data ... – Ben Bolker Aug 05 '15 at 15:43
  • Makes sense - my thought is that it may be better to use 4 by default, but then if the user specifies their own digits options to use that exactly, rather than take 3 away from it (what if the user specifies rounding to three digits? :0 ) – Señor O Aug 05 '15 at 15:46
  • 1
    note that it's `max(3, getOption("digits")-3)` -- not just "digits-3" – Ben Bolker Aug 05 '15 at 15:46
  • by "specifies their own digit options" do you mean that they have called `options("digits")` at some point (impossible to track if they have reset it), or that `getOption("digits") != 7`, or ... ? – Ben Bolker Aug 05 '15 at 15:48
  • `getOption("digits") != 7` is what I was thinking. – Señor O Aug 05 '15 at 15:49
  • Thank you for your helpful comments. This is definitely the source of the problem. – Rob Kabacoff Aug 06 '15 at 13:42
  • if this answered your question you're encouraged to click the check-mark to accept the answer ... – Ben Bolker Aug 06 '15 at 13:51