[R] Index matrix to pick elements from 3-dimensional matrix

From: juhana vartiainen <j.vartiainen_at_fief.se>
Date: Tue 26 Apr 2005 - 14:16:38 EST

Hi all

Suppose I have a dim=c(2,2,3) matrix A, say:

a b
c d

e f
g h

i j
k l

Suppose that I want to create a 2x2 matrix X, which picks elements from the above-mentioned submatrices according to an index matrix J referring to the "depth" dimension:
1 3
2 3

In other words, I want X to be
a j
g l

since the matrix J says that the (1,1)-element should be picked from A[,,1], the (1,2)-element should be picked from A[,,3], etc.

I have A and I have J. Is there an expression in A and J that creates X?




Juhana Vartiainen

docent in economics
Director, FIEF (Trade Union Foundation for Economic Research, Stockholm), http://www.fief.se
gsm +46 70 360 9915
office +46 8 696 9915
email juhana@fief.se
homepage http://www.fief.se/staff/Juhana/index.html

R-help@stat.math.ethz.ch mailing list
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Tue Apr 26 14:52:36 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:26 EST