From ligges at statistik.uni-dortmund.de  Tue May 20 09:35:08 2003
From: ligges at statistik.uni-dortmund.de (Uwe Ligges)
Date: Tue May 20 08:35:22 2003
Subject: [Rd] Extending %*%
In-Reply-To: <te2jcvkqn8uq9it881386oqi1n4j8ncakh@4ax.com>
References: <te2jcvkqn8uq9it881386oqi1n4j8ncakh@4ax.com>
Message-ID: <3EC9CC9C.2080204@statistik.uni-dortmund.de>

Duncan Murdoch wrote:
> I have lists of matrices stored in various ways.  I'd like to extend
> %*% to work on these.  Is this possible, or should I create my own new
> operator?
> 
> A simplified example would be as follows:
> 
> A <- list( A1, A2, A3)
> B <- list( B1, B2, B3)
> 
> where A1,...,B3 are all matrices, and I'd like A %*% B to return 
> 
> list( A1 %*% B1, A2 %*% B2, A3 %*% B3)
> 
> In the real case A and B are sometimes arrays, sometimes something
> else; lists haven't come up so far, but the principle should be the
> same.
> 
> Duncan Murdoch

The straightforward way without extending %*% (I feel that extending it 
is dangerous, in a way) is
   mapply("%*%", A, B, SIMPLIFY = FALSE)

Uwe Ligges


[Rd] Extending %*%
Uwe Ligges