## create a 3x3 magic square
x <- pracma::magic(3)
## Shift the matrix x to work along the second dimension.
## The permutation vector, perm, and the number of shifts, nshifts,
## are returned along with the shifted matrix.
sd <- shiftdata(x, 2)
## Shift the matrix back to its original shape.
y <- unshiftdata(sd)
## Rearrange Array to Operate on First Nonsingleton Dimension
x <- 1:5
sd <- shiftdata(x)
y <- unshiftdata(sd)
Run the code above in your browser using DataLab