R: Reverse Elements of a Vector or the Rows/Columns of Matrices,...

Rev {DescTools} | R Documentation

## Reverse Elements of a Vector or the Rows/Columns of Matrices, Tables or Data.frames

### Description

`Rev` provides a reversed version of its argument. It wraps the base function `rev` and provides an additional method for matrices and higher dimensional tables, such as to reverse the order of rows and columns.

### Usage

    Rev(x, ...)

    ## S3 method for class 'matrix'
    Rev(x, margin, ...)

    ## S3 method for class 'table'
    Rev(x, margin, ...)

    ## S3 method for class 'data.frame'
    Rev(x, margin, ...)

### Arguments

`x` | a vector, a matrix or a higher dimensional table to be reversed.
`margin` | vector of dimensions which to be reversed (1 for rows, 2 for columns, etc.).
`...` | the dots are passed to the matrix, resp. table interface.

### Author(s)

Andri Signorell <andri@signorell.net>

### See Also

`rev`, `order`, `sort`, `seq`

### Examples

    tab <- matrix( c( 1, 11, 111,
                      2, 22, 222,
                      3, 33, 333), byrow=TRUE, nrow=3)

    Rev(tab, margin=1)
    Rev(tab, margin=2)

    # reverse both dimensions
    Rev(tab, margin=c(1,2))

[Package DescTools version 0.99.24 Index]