Re: [R] can I rotate a matrix

2010-03-18 Thread Steve Taylor
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

Re: [R] can I rotate a matrix

2010-03-18 Thread Seeliger . Curt
> >> 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

Re: [R] can I rotate a matrix

2010-03-18 Thread Ted Harding
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

Re: [R] can I rotate a matrix

2010-03-18 Thread Seeliger . Curt
> > 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 >

Re: [R] can I rotate a matrix

2010-03-18 Thread Ted Harding
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] [,

Re: [R] can I rotate a matrix

2010-03-18 Thread Rolf Turner
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

Re: [R] can I rotate a matrix

2010-03-18 Thread Phil Spector
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

Re: [R] can I rotate a matrix

2010-03-18 Thread Greg Hirson
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

Re: [R] can I rotate a matrix

2010-03-18 Thread Henrique Dallazuanna
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

[R] can I rotate a matrix

2010-03-18 Thread dc896148
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