Gates, Michael BGI SF
2005-Nov-09 19:26 UTC
[R] Element-by-element multiplication operator?
Is there an element-by-element multiplication in R, like the .* operator in Matlab? eg: A (2x3) B (2x3) C=A.*B C (2x3) C = [[a11*b11 a12*b12 a13*b13]; [a21*b21 a22*b22 a23*b23]] I can't find one... Thanks -Mike Gates
See: http://cran.r-project.org/doc/contrib/R-and-octave-2.txt On 11/9/05, Gates, Michael BGI SF <Michael.Gates at barclaysglobal.com> wrote:> Is there an element-by-element multiplication in R, like the .* operator in Matlab? > > eg: A (2x3) > B (2x3) > C=A.*B > C (2x3) > C = [[a11*b11 a12*b12 a13*b13]; [a21*b21 a22*b22 a23*b23]] > > I can't find one... > > Thanks > > -Mike Gates > > ______________________________________________ > 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 >
On Wed, 9 Nov 2005, Gates, Michael BGI SF wrote:> Is there an element-by-element multiplication in R, like the .* operator in Matlab? > > eg: A (2x3) > B (2x3) > C=A.*B > C (2x3) > C = [[a11*b11 a12*b12 a13*b13]; [a21*b21 a22*b22 a23*b23]] > > I can't find one...It is the default: matrix(1:6,nrow=2) * cbind(1:2,1:2,1:2) [,1] [,2] [,3] [1,] 1 3 5 [2,] 4 8 12> > Thanks > > -Mike Gates > > ______________________________________________ > 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 >-- Dr. David Forrest drf at vims.edu (804)684-7900w drf5n at maplepark.com (804)642-0662h http://maplepark.com/~drf5n/
On 11/9/2005 2:26 PM, Gates, Michael BGI SF wrote:> Is there an element-by-element multiplication in R, like the .* operator in Matlab? > > eg: A (2x3) > B (2x3) > C=A.*B > C (2x3) > C = [[a11*b11 a12*b12 a13*b13]; [a21*b21 a22*b22 a23*b23]] > > I can't find one...Just use "*". If you want matrix multiplication, you'd use %*%. Duncan Murdoch
> Is there an element-by-element multiplication in R, like the .* operator in Matlab?How about *? a <- matrix(1:4, 2, 2) b <- matrix(4:7, 2, 2,) a * b Hadley
Gates, Michael BGI SF wrote:>Is there an element-by-element multiplication in R, like the .* operator in Matlab? > >eg: A (2x3) > B (2x3) >C=A.*B >C (2x3) >C = [[a11*b11 a12*b12 a13*b13]; [a21*b21 a22*b22 a23*b23]] > >I can't find one... > >mym <- matrix(1:4,2) myt <- matrix(5:8,2) > mym [,1] [,2] [1,] 1 3 [2,] 2 4 > myt [,1] [,2] [1,] 5 7 [2,] 6 8 > mym * myt [,1] [,2] [1,] 5 21 [2,] 12 32 HTH, Tobias
"Gates, Michael BGI SF" <Michael.Gates at barclaysglobal.com> writes:> Is there an element-by-element multiplication in R, like the .* operator in Matlab? > > eg: A (2x3) > B (2x3) > C=A.*B > C (2x3) > C = [[a11*b11 a12*b12 a13*b13]; [a21*b21 a22*b22 a23*b23]] > > I can't find one...It's * , plain and simple. The _other_ one is %*%.> Thanks > > -Mike Gates > > ______________________________________________ > 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 >-- O__ ---- Peter Dalgaard ??ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
davidr@rhotrading.com
2005-Nov-09 20:24 UTC
[R] Element-by-element multiplication operator?
A*B David L. Reiner> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch [mailto:r-help- > bounces at stat.math.ethz.ch] On Behalf Of Gates, Michael BGI SF > Sent: Wednesday, November 09, 2005 1:26 PM > To: r-help at stat.math.ethz.ch > Subject: [R] Element-by-element multiplication operator? > > Is there an element-by-element multiplication in R, like the .*operator> in Matlab? > > eg: A (2x3) > B (2x3) > C=A.*B > C (2x3) > C = [[a11*b11 a12*b12 a13*b13]; [a21*b21 a22*b22 a23*b23]] > > I can't find one... > > Thanks > > -Mike Gates > > ______________________________________________ > 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
What about A * B? -roger Gates, Michael BGI SF wrote:> Is there an element-by-element multiplication in R, like the .* operator in Matlab? > > eg: A (2x3) > B (2x3) > C=A.*B > C (2x3) > C = [[a11*b11 a12*b12 a13*b13]; [a21*b21 a22*b22 a23*b23]] > > I can't find one... > > Thanks > > -Mike Gates > > ______________________________________________ > 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 >-- Roger D. Peng | http://www.biostat.jhsph.edu/~rpeng/