[R] Column wise matrix multiplication

2012-02-20 Thread Graziano Mirata
Hi all, I am trying to multiply each column of a matrix such to have a unique resulting vector with length equal to the number of rows of the original matrix. In short I would like to do what prod(.) function in Matlab does, i.e. A -matrix(c(1:10),5,2) V = A[,1]*A[,2] Thank you Graziano

Re: [R] Column wise matrix multiplication

2012-02-20 Thread Dimitris Rizopoulos
Try apply(A, 1, prod) I hope it helps. Best, Dimitris On 2/20/2012 4:21 PM, Graziano Mirata wrote: Hi all, I am trying to multiply each column of a matrix such to have a unique resulting vector with length equal to the number of rows of the original matrix. In short I would like to do

Re: [R] Column wise matrix multiplication

2012-02-20 Thread Ted Harding
On 20-Feb-2012 Graziano Mirata wrote: Hi all, I am trying to multiply each column of a matrix such to have a unique resulting vector with length equal to the number of rows of the original matrix. In short I would like to do what prod(.) function in Matlab does, i.e. A -matrix(c(1:10),5,2)

Re: [R] Column wise matrix multiplication

2012-02-20 Thread Ted Harding
[See at end] On 20-Feb-2012 Ted Harding wrote: On 20-Feb-2012 Graziano Mirata wrote: Hi all, I am trying to multiply each column of a matrix such to have a unique resulting vector with length equal to the number of rows of the original matrix. In short I would like to do what prod(.)

Re: [R] Column wise matrix multiplication

2012-02-20 Thread Petr Savicky
On Mon, Feb 20, 2012 at 09:33:28PM -, Ted Harding wrote: [...] Unfortunately, there seems to be no equivalent for products (e.g. rowProds). But you can define one: rowProds - function(X){ apply(X,1,FUN=prod) } rowProds(A) # [1] 6 14 24 36 50 Even then, the result is