[R] Matrix element-by-element multiplication

Peter Langfelder peter.langfelder at gmail.com
Thu Jan 8 00:20:19 CET 2015


On Wed, Jan 7, 2015 at 3:15 PM, Peter Langfelder
<peter.langfelder at gmail.com> wrote:
> You can create a suitable matrix bb as below (note the byrow = TRUE argument)
>
> aa<-matrix(1:30,nrow=10,ncol=3); aa
> bb<-matrix(c(100,100,1),nrow=10,ncol=3, byrow = TRUE); bb
> dim(aa)
> dim(bb)
> aa * bb
>
>
> You can also use matrix multiplication, but that;s slightly more involved:

I should add that it will also be much slower if, as you say, you do
it on a much larger scale and the dimensions of bb are large.

Peter



More information about the R-help mailing list