[R] rev matrix

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Oct 15 08:42:05 CEST 2004

On Thu, 14 Oct 2004 lindsayv at unbc.ca wrote:

> Hello
> I am looking for a function which performs the same thing as rev but on a
> matrix rather then a vector, based on one column.
> I'd be happy to read the man page if such a function exists.

If I understand you, it is easy to do by indexing, but `based on >one< 
column' puzzles me and I take it you want each column reversed.

A <- matrix(1:20, 4, 5)
A[4:1, ]

or more generally

A[rev(seq(len=nrow(A))), ]

If that is not what you mean, please give us an example to look at.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list