[R] can I rotate a matrix
Greg Hirson
ghirson at ucdavis.edu
Thu Mar 18 20:50:51 CET 2010
Not sure why you are doing it, but you can do it like this:
m = matrix(c(1,3,4,2,2,5,1,6,3), nrow =3)
[,1] [,2] [,3]
[1,] 1 2 1
[2,] 3 2 6
[3,] 4 5 3
t(m)[ , ncol(m):1]
[,1] [,2] [,3]
[1,] 4 3 1
[2,] 5 2 2
[3,] 3 6 1
I hope that helps.
Greg
On 3/18/10 12:10 PM, 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.
>
--
Greg Hirson
ghirson at ucdavis.edu
Graduate Student
Agricultural and Environmental Chemistry
1106 Robert Mondavi Institute North
One Shields Avenue
Davis, CA 95616
More information about the R-help
mailing list