[R] "sum" bug?
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Fri Mar 22 08:30:20 CET 2002
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 at 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 at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list