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

Huntsinger, Reid reid_huntsinger at merck.com
Mon Jul 25 20:58:09 CEST 2005

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 at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Ravi Varadhan
Sent: Monday, July 25, 2005 1:39 PM
To: r-help at stat.math.ethz.ch
Subject: [R] A one-liner to create a 3-dim array



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,


	[[alternative HTML version deleted]]

R-help at stat.math.ethz.ch mailing list
PLEASE do read the posting guide!

More information about the R-help mailing list