[R] Column wise matrix multiplication

Dimitris Rizopoulos d.rizopoulos at erasmusmc.nl
Mon Feb 20 17:13:14 CET 2012


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 what prod(.) function in Matlab does, i.e.
>
> A<-matrix(c(1:10),5,2)
>
> V = A[,1]*A[,2]
>
> Thank you
>
> Graziano
>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/



More information about the R-help mailing list