Re: [R] Matrix multiplication by multple constants

2012-04-20 Thread Greg Snow
And another way is to remember properties of matrix multiplication: y %*% diag(x) On Fri, Apr 20, 2012 at 8:35 AM, David Winsemius wrote: > > On Apr 20, 2012, at 4:57 AM, Dimitris Rizopoulos wrote: > >> try this: >> >> x  <- 1:3 >> y  <- matrix(1:12, ncol = 3, nrow = 4) >> >> y * rep(x, each =

Re: [R] Matrix multiplication by multple constants

2012-04-20 Thread David Winsemius
On Apr 20, 2012, at 4:57 AM, Dimitris Rizopoulos wrote: try this: x <- 1:3 y <- matrix(1:12, ncol = 3, nrow = 4) y * rep(x, each = nrow(y)) Another way with a function specifically designed for that purpose: sweep(y, 2, x, "*") -- David. I hope it helps. Best, Dimitris On 4/20

Re: [R] Matrix multiplication by multple constants

2012-04-20 Thread Vincy Pyne
Dear Mr. Dimitris Rizopoulos, Thanks a lot for your great help. It worked nicely. I couldn't have figured it out. Thanks again. Regards Vincy --- On Fri, 4/20/12, Dimitris Rizopoulos wrote: From: Dimitris Rizopoulos Subject: Re: [R] Matrix multiplication by multple constants To: &

Re: [R] Matrix multiplication by multple constants

2012-04-20 Thread Dimitris Rizopoulos
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: Dear R helpers Suppose x<- c(1:3) y<- matrix(1:12, ncol = 3, nrow = 4) y [,1] [,2] [,3] [1,]159 [2,]2

[R] Matrix multiplication by multple constants

2012-04-20 Thread Vincy Pyne
Dear R helpers Suppose x  <- c(1:3) y  <- matrix(1:12, ncol = 3, nrow = 4) > y [,1] [,2] [,3] [1,]    1    5    9 [2,]    2    6   10 [3,]    3    7   11 [4,]    4    8   12 I wish to multiply 1st column of y by first element of x i.e. 1, 2nd column of y by 2nd element of x i.e. 2 an so