[R] Augment 'Matrix' matrices
Martin Maechler
maechler at stat.math.ethz.ch
Tue Jun 19 08:52:59 CEST 2007
>>>>> "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
More information about the R-help
mailing list