Development

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Element-by-element multiplication operator?

    8 answers - 364 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    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 (DOT) math.ethz.ch mailing list
    PLEASE do read the posting guide!
  • No.1 | | 565 bytes | |

    See:

    11/9/05, Gates, Michael BGI SF <Michael.Gates (AT) barclaysglobal (DOT) comwrote:
    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 (DOT) math.ethz.ch mailing list

    PLEASE do read the posting guide!

    R-help (AT) stat (DOT) math.ethz.ch mailing list

    PLEASE do read the posting guide!
  • No.2 | | 530 bytes | |

    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 (DOT) math.ethz.ch mailing list

    PLEASE do read the posting guide!
  • No.3 | | 484 bytes | |

    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

    R-help (AT) stat (DOT) math.ethz.ch mailing list

    PLEASE do read the posting guide!
  • No.4 | | 298 bytes | |

    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
    R-help (AT) stat (DOT) math.ethz.ch mailing list
    PLEASE do read the posting guide!
  • No.5 | | 686 bytes | |

    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

    R-help (AT) stat (DOT) math.ethz.ch mailing list

    PLEASE do read the posting guide!
  • No.6 | | 500 bytes | |

    "Gates, Michael BGI SF" <Michael.Gates (AT) barclaysglobal (DOT) comwrites:

    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 (DOT) math.ethz.ch mailing list

    PLEASE do read the posting guide!
  • No.7 | | 418 bytes | |

    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 (DOT) math.ethz.ch mailing list

    PLEASE do read the posting guide!
  • No.8 | | 535 bytes | |

    Wed, 9 Nov 2005, Gabor Grothendieck wrote:

    See:

    That is a really beautiful page. If the author is willing to update it to
    include some of the new functionality -- specifically N-dimensional
    arrays -- I'm sure I can help out. If there is new R functionality to
    include, I probably wouldn't know about it (I'm still learning R) but
    maybe someone else on the list would know.

    Mike

    R-help (AT) stat (DOT) math.ethz.ch mailing list

    PLEASE do read the posting guide!

Re: Element-by-element multiplication operator?


max 4000 letters.
Your nickname that display:
In order to stop the spam: 6 + 5 =
QUESTION ON "Development"

EMSDN.COM