[R] mixed formatting of integer and numeric (e. g., by summary.default())

Gerrit Eichner Gerrit.Eichner at math.uni-giessen.de
Fri Apr 5 17:46:03 CEST 2013

Hello, eveRybody,

I've been trying to find the origin for the following 

E. g., look at the number of digits in summary.defaults()'s output when 
NAs occur: in my example below the number of NA's is displayed as an 
integer, the rest as numeric (floating point numbers):

> summary.default( c( 1:2, NA))
    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's
    1.00    1.25    1.50    1.50    1.75    2.00       1

However, if I define my own summary function using - from my current point 
of view - the same commands as the respective part of summary.default() 
does, i. e.,

> my.summary <- function( object,
                           digits = max( 3, getOption("digits")) - 3) {
   nas <- is.na( object)
   object <- object[ !nas]
   qq <- stats::quantile( object)
   qq <- signif( c( qq[ 1L:3L], mean( object), qq[ 4L:5L]),
                 digits = digits)
   names( qq) <- c( "Min.", "1st Qu.", "Median", "Mean", "3rd Qu.",
   v <- if( any( nas)) c( qq, NAs = sum( nas)) else qq
   class( v) <- c("summaryDefault", "table")

I get the following (look at the number of NA's):

> my.summary( c( 1:2, NA))
    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.     NAs
    1.00    1.25    1.50    1.50    1.75    2.00    1.00

Could somebody please point me to what I'm overlooking?

  Thanks & best regards  --  Gerrit

> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)

[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

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

other attached packages:
[1] xtable_1.7-0     lattice_0.20-10  fortunes_1.5-0   svSocket_0.9-53
[5] TinnR_1.0-5      R2HTML_2.2       Hmisc_3.10-1     survival_2.36-14

loaded via a namespace (and not attached):
[1] cluster_1.14.3 grid_2.15.2    svMisc_0.9-65  tools_2.15.2

Dr. Gerrit Eichner                   Mathematical Institute, Room 212
gerrit.eichner at math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109        http://www.uni-giessen.de/cms/eichner

More information about the R-help mailing list