Re: [R] Augment 'Matrix' matrices

From: Martin Maechler <>
Date: Tue, 19 Jun 2007 08:52:59 +0200

>>>>> "SH" == Scott Hyde <> >>>>> on Mon, 18 Jun 2007 16:59:00 -1000 (HST) writes:

    SH> Martin, How does Matrix implement augmented matrices? I     SH> tried this and got the expected result:

{Replying to R-help, since this question has come up several  times }

>> V=matrix(1,2,3)
>> V=cbind(V,V)
>> V

    SH>      [,1] [,2] [,3] [,4] [,5] [,6]
    SH> [1,]    1    1    1    1    1    1
    SH> [2,]    1    1    1    1    1    1

    SH> But when I did it with Matrix instead I got:

>> library(Matrix)

>> V=Matrix(1,2,3)
>> V=cbind(V,V)
>> V

    SH> V V
    SH> [1,] ? ?

cbind() and rbind() cannot work with S4 objects because their first formal argument is '...'
[ and with S3 objects they only work insofar as S3 generics can   "work": i.e. they only "work" when the first argument is of the   respective class, but fail, e.g. for cbind(1, <object>)   when <object> is of a non-standard S3 class. ]
In earlier versions of Matrix, there was a sophisticated "hack" that made cbind() and rbind() "work".

But because it was a hack, and some people called it "horrible" rather than "sophisticated", we had to give it up. {well, the really compelling argument was an example of, <list of length 1000>) which was *very* inefficient}

Instead, cbind2() and rbind2() have been written a few R versions ago to be used as (S4) generic functions. --> help(cbind2)

In 'Matrix', we also define cBind() and rBind() to be used as direct (n-argument) substitutes for cbind() or rbind(), respectively.

Martin mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Tue 19 Jun 2007 - 07:00:35 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 19 Jun 2007 - 08:32:22 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.