Reverse a Matrix by Rows, Columns or Both
revmat.Rd
Reverses the order of entire matrix rows, columns or both.
Usage
revmat(x, type = c("byrow", "bycolumn", "byboth"))
Details
Depending on the argument type
, this function reverses the order of entire rows, columns or both of a matrix,
including any dimnames if present.
Examples
m <- matrix(1:9, nrow = 3, byrow = TRUE, dimnames = list(paste0("x", 1:3), paste0("y", 1:3)))
m
#> y1 y2 y3
#> x1 1 2 3
#> x2 4 5 6
#> x3 7 8 9
revmat(m)
#> y1 y2 y3
#> x3 7 8 9
#> x2 4 5 6
#> x1 1 2 3
revmat(m, "bycol")
#> y3 y2 y1
#> x1 3 2 1
#> x2 6 5 4
#> x3 9 8 7
revmat(m, "byboth")
#> y3 y2 y1
#> x3 9 8 7
#> x2 6 5 4
#> x1 3 2 1
rm(m)