Skip to content

Matrix multiplication by multple constants

5 messages · Dimitris Rizopoulos, Vincy Pyne, David Winsemius +1 more

#
try this:

x  <- 1:3
y  <- matrix(1:12, ncol = 3, nrow = 4)

y * rep(x, each = nrow(y))


I hope it helps.

Best,
Dimitris
On 4/20/2012 10:51 AM, Vincy Pyne wrote:

  
    
#
On Apr 20, 2012, at 4:57 AM, Dimitris Rizopoulos wrote:

            
Another way with a function specifically designed for that purpose:

sweep(y, 2, x, "*")

--  
David.
David Winsemius, MD
West Hartford, CT
#
And another way is to remember properties of matrix multiplication:

y %*% diag(x)
On Fri, Apr 20, 2012 at 8:35 AM, David Winsemius <dwinsemius at comcast.net> wrote: