[R] Matrix rotation

Benjamin Lloyd-Hughes blh at cpom.ucl.ac.uk
Thu Nov 24 17:15:58 CET 2005


Dearest All,

Ok so I've had a couple of glasses of wine over lunch today... This is 
likely to be trivial but I'm struggling to find a more elegant way to 
obtain the following matrix rotations:

 > M <- matrix(c(1,0,0,0), ncol=2)
 > M
      [,1] [,2]
[1,]    1    0
[2,]    0    0
 > N <- abind(M[2,],M[1,],along=2)
 > N
      [,1] [,2]
[1,]    0    1
[2,]    0    0
 > P <- abind(N[2,],N[1,],along=2)
 > P
      [,1] [,2]
[1,]    0    0
[2,]    0    1
 > Q <- abind(P[,2],P[,1],along=2)
 > Q
      [,1] [,2]
[1,]    0    0
[2,]    1    0

And, more generally wish to rotate a n-dimensional data cube about some 
specified axis.

Cheers, Ben




More information about the R-help mailing list