Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

arev

Reverses some dimensions; a generalization of rev


Description

A multidimensional generalization of rev(): given an array a, and a Boolean vector swap, return an array of the same shape as a but with dimensions corresponding to TRUE elements of swap reversed. If swap is not Boolean, it is interpreted as the dimensions along which to swap.

Usage

arev(a, swap = TRUE)

Arguments

a

Array to be reversed

swap

Vector of Boolean variables. If swap[i] is TRUE, then dimension i of array a is reversed. If swap is of length one, recycle to length(dim(a))

Details

If swap is not Boolean, it is equivalent to 1:n %in% swap (where n is the number of dimensions). Thus multiple entries are ignored, as are entries greater than n.

If a is a vector, rev(a) is returned.

Function arev() handles zero-extent dimensions as expected.

Function arev() does not treat singleton dimensions specially, and is thus different from Octave's flipdim(), which (if supplied with no second argument) flips the first nonsingleton dimension. To reproduce this, use arev(a,fnsd(a)).

Author(s)

Robin K. S. Hankin

See Also

Examples

a <- matrix(1:42,6,7)
arev(a)  #Note swap defaults to TRUE

b <- magichypercube.4n(1,d=4)
arev(b,c(TRUE,FALSE,TRUE,FALSE))

magic

Create and Investigate Magic Squares

v1.5-9
GPL-2
Authors
Robin K. S. Hankin
Initial release
2018-09-14

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.