mirror_matrix: Mirror a matrix horizontally

View source: R/number_tools.R

mirror_matrixR Documentation

Mirror a matrix horizontally

Description

Mirror a matrix horizontally

Usage

mirror_matrix(mat, MARGIN = 2)

Arguments

mat

(Matrix) A matrix object

MARGIN

(Integer) '1' mirrors the order of rows, '2' mirrors the order of columns.

Value

A version of 'mat' with its columns or rows in reversed order. Names are preserved if the matrix has any.

Examples

m <- matrix(1:6, ncol = 2, nrow = 3, byrow = FALSE)
m

#>      [,1] [,2]
#> [1,]    1    4
#> [2,]    2    5
#> [3,]    3    6

# Just like apply(), MARGIN = 1 is rows and MARGIN = 2 is cols.

mirror_matrix(m, 2)

#>      [,1] [,2]
#> [1,]    4    1
#> [2,]    5    2
#> [3,]    6    3

mirror_matrix(m, 1)

#>      [,1] [,2]
#> [1,]    3    6
#> [2,]    2    5
#> [3,]    1    4


DesiQuintans/desiderata documentation built on April 9, 2023, 5:43 a.m.