[R] Summary bug?
Martin Maechler
maechler at stat.math.ethz.ch
Tue Oct 19 08:26:53 CEST 1999
Alvaro> Hi, It seems that there's a bug in summary, in the
Alvaro> max. output... but max() alone works fine.
Alvaro> hw04.dframe$area
Alvaro> ...
Alvaro> [41] 1790 1380 1296 2745 798 2306 438649 1481 1559 2450
Alvaro> ...
Alvaro> summary(hw04.dframe)
Alvaro> area
Alvaro> Min. : 798
Alvaro> 1st Qu.: 1349
Alvaro> Median : 1690
Alvaro> Mean : 6962
Alvaro> 3rd Qu.: 2306
Alvaro> Max. :438600 ### should read 438649
Alvaro> or, to the point,
Alvaro> summary(hw04.dframe$area)
Alvaro> Min. 1st Qu. Median Mean 3rd Qu. Max.
Alvaro> 798 1349 1690 6962 2306 438600
Alvaro> ### should be 438649
Alvaro> max(hw04.dframe$area)
Alvaro> [1] 438649
Alvaro> is.data.frame(hw04.dframe)
Alvaro> [1] TRUE
There's no bug. It's a feature -- inherited from S
> args(summary.default)
or ?summary {please read the doc before posting...}
shows you
function (object, ..., digits = max(3, .Options$digits - 3))
I.e. by default, options(digits = 7) and you get four digits.
Usually with numbers of vastly different size, you get exponential
representation with 4 digits each,
> summary(as.data.frame(x <- c(rnorm(20),pi* 10^c(0:2,5))))
x
Min. :-2.056e+00
1st Qu.:-1.023e+00
Median : 2.774e-01
Mean : 1.310e+04
3rd Qu.: 1.428e+00
Max. : 3.142e+05
but
I agree that in the above case it can be quite confusing
as e.g. in the following (just a different random sample)
> summary(as.data.frame(x <- c(rnorm(20),pi* 10^c(0:2,4))))
x
Min. : -1.3250
1st Qu.: -0.4386
Median : 0.2091
Mean : 1324.0000
3rd Qu.: 0.7687
Max. :31420.0000
-------
"Solution":
Use summary(...., digits= 10)
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list