Camford Oxbridge
Camford Oxbridge

Reputation: 894

Transposed Array from array

Let A[ , , ] be an array of dimension [2,3,4]

For example,

A <- array(1:24,c(2,3,4))

I want to get a new array B of dimension [2,4,3] such that

B[i,j,k]=A[i,k,j]

for all i,j,k.

Upvotes: 2

Views: 54

Answers (1)

G. Grothendieck
G. Grothendieck

Reputation: 269526

Use aperm:

aperm(A, c(1, 3, 2))

Upvotes: 3

Related Questions