[R] summary() vs mean()

Marc R. Feldesman feldesmanm at pdx.edu
Thu Feb 1 04:14:42 CET 2001


Forgive what may seem to be a trivial question/problem.

Below is some simple R 1.2.1(Windows) code with output.

 > summary(mammals, digits=10)
        Name    Body.Weight      Brain.Weight
  Red Fox :1   Min.   :   3.0   Min.   :  26.0
  Pig     :1   1st Qu.:  35.5   1st Qu.: 138.5
  Man     :1   Median : 100.0   Median : 406.0
  Kangaroo:1   Mean   : 761.2   Mean   :1000.0
  Jaguar  :1   3rd Qu.: 493.0   3rd Qu.: 667.5
  Horse   :1   Max.   :6654.0   Max.   :5712.0
  (Other) :9
 > mean(mammals[,3])
[1] 1000.467  # <---summary() reports it as 1000.0
 > mean(mammals[,2])
[1] 761.2 # <- summary() reports it as 761.2

I'm puzzled why the Brain.Weight mean from summary() is different from 
mean(mammals[,3]), while the Body.Weight means are identical in the two 
functions.  This isn't limited to R; I've observed the same thing in S-Plus 
2000 (and v.6 beta).

I can get the "right" answer in S-Plus using the digits argument (setting 
digits=8), but this argument doesn't seem to have any effect in R 1.2.1.  I 
*did* use it the way it is illustrated in the help file as well (e.g.

summary(mammals, digits=max(10, getOption("digits")))
)
with the same results as above.

So, I guess I have two questions:

1)  Why does S (in both S-Plus and R 1.2.1) produce different values for 
the means in the second variable but not the first?

2)  Why does the digits argument seem not to have any effect in R 1.2.1's 
summary()?

P.S.  I also pasted the example code from the summary help file into the R 
1.2.1 window.  The digits argument doesn't change the results there either.







Dr. Marc R. Feldesman
email:  feldesmanm at pdx.edu
email:  feldesman at attglobal.net
fax:    503-725-3905

"Don't know where I'm going.
Don't like where I've been.
There may be no exit.
But hell, I'm going in."  Jimmy Buffett

Powered by Superchoerus - the 700 MHz Coppermine Box

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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