Re: [R] horizontal direct product

From: Thomas Lumley <>
Date: Sat 26 Aug 2006 - 10:21:16 EST

On Fri, 25 Aug 2006, Luke Keele wrote:

> II am translating some gauss code into R, and gauss has a matrix
> product function called the horizontal direct product (*~), which is
> some sort of variant on the Kronecker product.
> For example if x is 2x2 and y is 2x2
> the horizontal direct product, z, of x and y is defined (in the Gauss
> manual) as:
> row 1 = x11*y11 x11*y12 x12*y11 x12*y12
> row 2 = x21*y21 x21*y22 x22*y21 x22*y22

It looks as though
"%~%" <- function (A, B)

     m <- ncol(A)
     n <- ncol(B)
     A[, rep(1:m, each = n)] * B[, rep(1:n, m)]

would do it.


Thomas Lumley			Assoc. Professor, Biostatistics	University of Washington, Seattle

______________________________________________ mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Sat Aug 26 10:26:52 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 26 Aug 2006 - 12:27:56 EST.

Mailing list information is available at Please read the posting guide before posting to the list.