Skip to content

rowsum() may return a vector instead of a matrix (PR#3737)

4 messages · Thomas Lumley, Brian Ripley, David Brahm

#
If all rows are in the same "group", rowsum() returns a vector instead of a
(1xN) matrix, contrary to documentation:

R> print(z <- rowsum(matrix(1:12, 3,4), rep("x",3)))
   [1]  6 15 24 33
R> dim(z)
   NULL

It worked correctly in version 1.4.0 but was broken by version 1.6.1.  I'm
currently using 1.7.1 under Solaris 2.8.


--please do not edit the information below--

Version:
 platform = sparc-sun-solaris2.8
 arch = sparc
 os = solaris2.8
 system = sparc, solaris2.8
 status = 
 major = 1
 minor = 7.1
 year = 2003
 month = 06
 day = 16
 language = R

Search Path:
 .GlobalEnv, package:misc, package:io, package:arrays, package:ls1, package:obsi, package:g.data, package:db, package:ts, package:ctest, Autoloads, package:base
#
On Wed, 13 Aug 2003 brahm@alum.mit.edu wrote:

            
Yes, and it appears to be deliberate since rowsum.default() ends with
drop(rval), though I don't remember why it was this way.

Is there a strong preference for changing the function vs changing the
documentation?

	-thomas
#
On Tue, 12 Aug 2003, Thomas Lumley wrote:

            
I'd change the function.  The Therneau original function of this name 
returns a 1xN matrix, and it is easier to drop() that to reinstate.
#
I wrote:
Thomas Lumley <tlumley@u.washington.edu> replied:
I could live with it either way, but I will point out that the "Examples"
section implies an equivalence between:
  R> xsum <- rowsum(x, group)
and
  R> xsum2 <- tapply(x, list(group[row(x)], col(x)), sum)
  R> xsum3 <- aggregate(x, list(group), sum)
which is broken by this new behavior; xsum2 and xsum3 are (1xN) matrices.