Re: [R] A one-liner to create a 3-dim array

From: Huntsinger, Reid <reid_huntsinger_at_merck.com>
Date: Tue 26 Jul 2005 - 04:58:09 EST


I think this works:

B <- aperm(rep(t(A),n)*rep(A,rep(n,n*m)), perm=c(1,3,2))

Reid Huntsinger

-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch
[mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Ravi Varadhan Sent: Monday, July 25, 2005 1:39 PM
To: r-help@stat.math.ethz.ch
Subject: [R] A one-liner to create a 3-dim array

Hi,  

I would like to write a one-line R code to create a 3-dim array, B, of dimension (n,n,m) from a matrix, A, of dimension (m,n) such that the i-th element of the 3-dim array, B[, , i] is the outer product of the i-th row of A.  

Thanks for any help,

Ravi.

        [[alternative HTML version deleted]]



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

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 Received on Tue Jul 26 05:02:45 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:34:01 EST