Re: [R] A matrix calculation

2009-08-23 Thread Erich Neuwirth
as.vector(t(mat[7:1,])) On Aug 23, 2009, at 9:35 PM, David Winsemius wrote: There is another "matrix" strategy that succeeds, although it is clearly less economical that the transpose approach: matrix(mat[7:1, ], ncol=nrow(mat), byrow=TRUE) # will transpose the matrix I offer this only

Re: [R] A matrix calculation

2009-08-23 Thread David Winsemius
There is another "matrix" strategy that succeeds, although it is clearly less economical that the transpose approach: matrix(mat[7:1, ], ncol=nrow(mat), byrow=TRUE) # will transpose the matrix I offer this only as a reminder that the byrow= parameter is available when appropriate. --

Re: [R] A matrix calculation

2009-08-23 Thread Ted Harding
The problem with David's proposal is revealed by: mat[7:1,] # [,1] [,2] [,3] # [1,]7 14 21 # [2,]6 13 20 # [3,]5 12 19 # [4,]4 11 18 # [5,]3 10 17 # [6,]29 16 # [7,]18 15 which simply reverses the rows. Then: c(

Re: [R] A matrix calculation

2009-08-23 Thread David Winsemius
On Aug 23, 2009, at 2:53 PM, Bogaso wrote: No no, I actually want following result : 7, 14, 21, 6, 13, 20, 5, 12, 19, Ooops. That is what I thought you wanted, but I didn't check very carefully, did I? c(apply(mat[7:1,],1,I) ) # the I() function just returns "it

Re: [R] A matrix calculation

2009-08-23 Thread Michael Knudsen
On Sun, Aug 23, 2009 at 8:53 PM, Bogaso wrote: > No no, I actually want following result : > > 7,   14,   21, 6,   13,   20, 5,   12,   19, How about this? x = c() for (i in 7:1) x = c(x,mat[i,]) Guess that would do the trick. Best, Michael -- Michael Knudsen micknud...@gmail.com

Re: [R] A matrix calculation

2009-08-23 Thread Peter Dalgaard
Bogaso wrote: No no, I actually want following result : 7, 14, 21, 6, 13, 20, 5, 12, 19, c(t(mat[7:1,])) then. David Winsemius wrote: On Aug 23, 2009, at 2:37 PM, Bogaso wrote: I have suppose a matrix like that mat <- matrix(1:21, 7) mat [,1] [,2] [,3]

Re: [R] A matrix calculation

2009-08-23 Thread Bogaso
No no, I actually want following result : 7, 14, 21, 6, 13, 20, 5, 12, 19, David Winsemius wrote: > > > On Aug 23, 2009, at 2:37 PM, Bogaso wrote: > >> >> I have suppose a matrix like that >> >>> mat <- matrix(1:21, 7) >>> mat >> [,1] [,2] [,3] >> [1,]18

Re: [R] A matrix calculation

2009-08-23 Thread David Winsemius
On Aug 23, 2009, at 2:37 PM, Bogaso wrote: I have suppose a matrix like that mat <- matrix(1:21, 7) mat [,1] [,2] [,3] [1,]18 15 [2,]29 16 [3,]3 10 17 [4,]4 11 18 [5,]5 12 19 [6,]6 13 20 [7,]7 14 21 From this matrix, I want t

[R] A matrix calculation

2009-08-23 Thread Bogaso
I have suppose a matrix like that > mat <- matrix(1:21, 7) > mat [,1] [,2] [,3] [1,]18 15 [2,]29 16 [3,]3 10 17 [4,]4 11 18 [5,]5 12 19 [6,]6 13 20 [7,]7 14 21 >From this matrix, I want to create a vector like tha : c(mat[7,], mat