Re: [R] multiply two matrixes with the different dimension column by column

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Fri 13 Oct 2006 - 12:58:41 GMT

Here are two ways:

  1. Using inner from:

         http://tolstoy.newcastle.edu.au/R/help/05/04/3709.html

    try:

         array(inner(t(X), Y, "*"), c(4, 21))

2. using model.matrix get all terms and interactions and eliminate the non-interactions:

         model.matrix(~ X * Y - X - Y - 1)

On 10/13/06, Majid Iravani <majid.iravani@wsl.ch> wrote:
> Dear all,
> I would like to multiply two matrixes with the different dimension column
> by column. Let make an example:
> If I have two matrixes "X" and "Y"as follow:
>
> X<- matrix(1:12, nrow=4, ncol=3, dimnames=list(c("A","B","C","D"),
> c("stage1","stage2","stage3")))
> Y<- matrix(1:28, nrow=4, ncol=7, dimnames=list(c("A","B","C","D"),
> c("site1","site2","site3","site4","site5", "site6","site7")))
>
> I would like to multiply first column of the "Y"matrix (site1) to the all
> of the columns in "X"matrix. Then, the product will be three new columns
> (for example:site1stage1, site1stage2 and site1stage3 or something like
> this) which I want to add to "Y"matrix. As my site (Y) dataset has too many
> columns, it's not easy to do it in Excel and I'm looking for a command in R
> to prepare a new data frame for more analysis. So I would greatly
> appreciate if anybody can help me in this case.
> Thanks in advance

> Majid
> --------------------------------------------------------------------------------
> Majid Iravani
> PhD Student
> Swiss Federal Research Institute WSL
> Research Group of Vegetation Ecology
> Zürcherstrasse 111 CH-8903 Birmensdorf Switzerland
> Phone: +41-1-739-2693
> Fax: +41-1-739-2215
> Email: Majid.iravani@wsl.ch
> http://www.wsl.ch/staff/majid.iravani/
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>



R-help@stat.math.ethz.ch 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. Received on Sat Oct 14 10:26:58 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 14 Oct 2006 - 01:30:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.