Re: [R] "sum" bug?

About this list Date view Thread view Subject view Author view Attachment view

From: Prof Brian D Ripley (ripley@stats.ox.ac.uk)
Date: Fri 22 Mar 2002 - 18:30:20 EST


Message-id: <Pine.GSO.4.44.0203220724290.19239-100000@auk.stats>

On Thu, 21 Mar 2002, Kenneth Cabrera wrote:

> Dear R users and developers:
>
> I got this message when I try to make the summary of a numeric variable,

It's not really numeric = double: it is integer. Try typeof(Dep).

> > summary(Dep)
>
> Min. 1st Qu. Median Mean 3rd Qu. Max.
> 0.000e+00 1.192e+07 2.739e+07 6.538e+07 1.858e+09
> Warning message:
> Integer overflow in sum(.); use sum(as.numeric(.))
>
> and it fails to make the sum (for calculate the mean), but I don't
> understand the "Integer overflow"
>
> If I type the following command,
>
> > summary(as.numeric(Dep))
> Min. 1st Qu. Median Mean 3rd Qu. Max.
> 0.000e+00 1.192e+07 2.739e+07 5.306e+07 6.538e+07 1.858e+09
>
> it works fine.... but I still don't undertand way it doesn't work without
> the "as.numeric" coerce, when other functions like "sd()" worked fine.

Because a sum of integers is considered to be an integer, and mean(x)
is sum(x)/length(x) (in essence). I think mean should coerce integers (or
logicals) to double.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Wed 16 Oct 2002 - 11:57:08 EST