Re: [R] Augment 'Matrix' matrices

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Tue, 19 Jun 2007 08:52:59 +0200

>>>>> "SH" == Scott Hyde <hydes_at_byuh.edu> >>>>> 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  do.call(rbind, <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



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.