[Rd] Unexpected behavior of colSums (rowSums) when the input matrix has zero rows (columns) (PR#7775)

htang at hpl.hp.com htang at hpl.hp.com
Wed Apr 6 02:45:05 CEST 2005


Hi all,

colSums() does not work as I expect when there are no rows.  For example:

> x = matrix(0, nrow=0, ncol=5)
> colSums(x)
Error in colSums(x, n, prod(dn), na.rm) : invalid value of n

I expected to get 0's, as is given by apply():

> apply(x, 2, sum, na.rm=TRUE)
[1] 0 0 0 0 0

This behavior is also inconsistent with the case when NA's are removed:

> colSums(matrix(NA, nrow=1, ncol=5), na.rm=TRUE)
[1] 0 0 0 0 0

(This latter case is described in the documentation.)

The same problem occurs with rowSums(), of course.

Thanks,
Hsiu-Khuern.

--please do not edit the information below--

Version:
 platform = i386-pc-linux-gnu
 arch = i386
 os = linux-gnu
 system = i386, linux-gnu
 status =
 major = 2
 minor = 0.1
 year = 2004
 month = 11
 day = 15
 language = R

Search Path:
 .GlobalEnv, package:methods, package:stats, package:graphics, package:grDevices, package:utils, Autoloads, package:base



More information about the R-devel mailing list