[R] "flipping" vector and matrix

Rainer M Krug Rainer+R-help at krugs.de
Tue Oct 23 12:45:18 CEST 2007


Hi

I have a vector

x <- c(1, 2, 3, 4, 5)

and I want to "flip" it around, i.e. I need

5, 4, 3, 2, 1

Is there a ssolution apart from

y <- x[length(x):1]


I am also looking for the same for a matrix M, i.e.

1 2 3
4 5 6
7 8 9

should become

7 8 9
4 5 6
1 2 3

again, I am using

M[1:dim(M)[1], dim(M)[2]:1]


Thanks

Rainer



More information about the R-help mailing list