How about this for a more generalised matrix rotation function (works with
1-column and 1-row matrices too) ...
rotate = function(mat) t(mat[nrow(mat):1,,drop=FALSE])
>>>
From:
To:
Date: 19/Mar/2010 10:15a
Subject: Re: [R] can I rotate a matrix
> Now that *is* neat!
Thanks!
U
> >> mat
> >> # [,1] [,2] [,3]
> >> # [1,]121
> >> # [2,]326
> >> # [3,]453
> >>
> >> matrix(rev(mat),nrow=3,byrow=TRUE)[(3:1),]
> >> # [,1] [,2] [,3]
> >> # [1,]431
> >> # [2,]522
> >> # [3,]361
On 18-Mar-10 20:25:22, seeliger.c...@epamail.epa.gov wrote:
>> > I want to be able to rotate a matrix 90 degrees, clockwise.
>> > For > example,
>> >> mat
>> > [,1] [,2] [,3]
>> > [,1] 12 1
>> > [,2] 32 6
>> > [,3] 45 3
>> >
>> > I want to rotate it, so that it
> > I want to be able to rotate a matrix 90 degrees, clockwise.
> > For > example,
> >> mat
> > [,1] [,2] [,3]
> > [,1] 12 1
> > [,2] 32 6
> > [,3] 45 3
> >
> > I want to rotate it, so that it looks like this...
> > [,1] [,2] [,3]
> > [,1] 43 1
>
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] 12 1
> [,2] 32 6
> [,3] 45 3
>
> I want to rotate it, so that it looks like this...
> [,1] [,2] [,
On 19/03/2010, at 8:10 AM, dc896148 wrote:
>
> useR's,
> I want to be able to rotate a matrix 90 degrees, clockwise. For example,
>> mat
> [,1] [,2] [,3]
> [,1] 12 1
> [,2] 32 6
> [,3] 45 3
>
> I want to rotate it, so that it looks like this...
> [,1] [,2
I belive that
apply(t(mat),2,rev)
[,1] [,2] [,3]
[1,]163
[2,]225
[3,]134
will do what you want. I'll leave it up to you to decide
whether it's straightforward.
- Phil Spector
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,]121
[2,]326
[3,]453
t(m)[ , ncol(m):1]
[,1] [,2] [,3]
[1,]431
[2,]522
[3,]361
I hope that
Try this:
t(mat[3:1,])
On Thu, Mar 18, 2010 at 4: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
useR's,
I want to be able to rotate a matrix 90 degrees, clockwise. For example,
> mat
[,1] [,2] [,3]
[,1] 12 1
[,2] 32 6
[,3] 45 3
I want to rotate it, so that it looks like this...
[,1] [,2] [,3]
[,1] 43 1
[,2] 52 2
[,3] 36
10 matches
Mail list logo