On Fri, 25 Mar 2011, William Dunlap wrote:

(a) In R 2.12.2 rowsum can overflow if given an integer input:
 > rowsum(c(2e9L, 2e9L), c("a", "a"))
         [,1]
 a -294967296
 > 2^32 + .Last.value
    [,1]
 a 4e+09
Should it be changed to coerce its x argument to numeric
(double precision) so it always returns a numeric output?

No, I don't think so. But it should return NA on overflow (as sum() does), and I've altered pre-2.13.0 to do so.

(b) When rowsum is given an x containing both NaN and NA it
appears to use the last of the NaN/NA entries to determine
if the output is NaN or NA while the `+` function uses the
first:
 > z <- cbind( c(NA,NA), c(NA,NaN), c(NaN,NA), c(NaN,NaN))
 > rowsum(z, c("a","a"))
   [,1] [,2] [,3] [,4]
 a   NA  NaN   NA  NaN
 > z[1,,drop=FALSE] + z[2,,drop=FALSE]
      [,1] [,2] [,3] [,4]
 [1,]   NA   NA  NaN  NaN

Which is not a bug: R does not claim to be consistent about this (except for a few documented functions), and there are lots of instances of this.

(The name rowsum is a metabug, since it may be confused
with the entirely different rowSums, but it has been around
for a long time.)

A lot longer than rowSums ...

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

--
Brian D. Ripley,                  rip...@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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to