[R] Fwd: Matrix rotation

Paul Roebuck roebuck at mdanderson.org
Mon Nov 28 11:35:59 CET 2005


On Thu, 24 Nov 2005, Benjamin Lloyd-Hughes wrote:

> Ok I warned you that I'd been drinking! What I really meant was
> something to go from:
>
>       [,1] [,2]
> [1,]    1    2
> [2,]    4    3
>
> to
>
>       [,1] [,2]
> [1,]    4    1
> [2,]    3    2
>
> to
>
>       [,1] [,2]
> [1,]    3    4
> [2,]    2    1
>
> to
>
>       [,1] [,2]
> [1,]    2    3
> [2,]    1    4
>


Another possible solution...

> library(matlab)
> x <- matrix(c(1,2,4,3), nrow=2, byrow=TRUE)
> x
     [,1] [,2]
[1,]    1    2
[2,]    4    3
> matlab::rot90(x, 3)
     [,1] [,2]
[1,]    4    1
[2,]    3    2
> matlab::rot90(x, 2)
     [,1] [,2]
[1,]    3    4
[2,]    2    1
> matlab::rot90(x, 1)
     [,1] [,2]
[1,]    2    3
[2,]    1    4

----------------------------------------------------------
SIGSIG -- signature too long (core dumped)




More information about the R-help mailing list