On 18-Mar-10 19:10:46, dc896148 wrote: > useR's, > I want to be able to rotate a matrix 90 degrees, clockwise. > For > example, >> mat > [,1] [,2] [,3] > [,1] 1 2 1 > [,2] 3 2 6 > [,3] 4 5 3 > > I want to rotate it, so that it looks like this... > [,1] [,2] [,3] > [,1] 4 3 1 > [,2] 5 2 2 > [,3] 3 6 1 > > Does anyone know a quick and straightforward way to do this? > > Thanks in advance. > --
mat # [,1] [,2] [,3] # [1,] 1 2 1 # [2,] 3 2 6 # [3,] 4 5 3 matrix(rev(mat),nrow=3,byrow=TRUE)[(3:1),] # [,1] [,2] [,3] # [1,] 4 3 1 # [2,] 5 2 2 # [3,] 3 6 1 How's that? (But straightforward? Straightbackward, more like). Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.hard...@manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 18-Mar-10 Time: 19:57:07 ------------------------------ XFMail ------------------------------ ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.