Skip to contents

90° clockwise matrix rotation.

Applied twice, the function provide the mirror matrix, according to vertical and horizontal symmetry.

Usage

mat_rotate(data, safer_check = TRUE)

Arguments

data

Matrix (matrix class).

safer_check

Single logical value. Perform some "safer" checks (see https://github.com/safer-r)? If TRUE, checkings are performed before main code running: 1) R classical operators (like "<-") not overwritten by another package because of the R scope and 2) required functions and related packages effectively present in local R lybraries. Set to FALSE if this fonction is used inside another "safer" function to avoid pointless multiple checkings.

Value

The modified matrix.

Author

Gael Millot <gael.millot@pasteur.fr>

Yushi Han <yushi.han2000@gmail.com>

Haiding Wang <wanghaiding442@gmail.com>

Examples

obs <- matrix(1:10, ncol = 1) ; obs ; mat_rotate(obs)
#>       [,1]
#>  [1,]    1
#>  [2,]    2
#>  [3,]    3
#>  [4,]    4
#>  [5,]    5
#>  [6,]    6
#>  [7,]    7
#>  [8,]    8
#>  [9,]    9
#> [10,]   10
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> [1,]   10    9    8    7    6    5    4    3    2     1

obs <- matrix(LETTERS[1:10], ncol = 5) ; obs ; mat_rotate(obs)
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,] "A"  "C"  "E"  "G"  "I" 
#> [2,] "B"  "D"  "F"  "H"  "J" 
#>      [,1] [,2]
#> [1,] "B"  "A" 
#> [2,] "D"  "C" 
#> [3,] "F"  "E" 
#> [4,] "H"  "G" 
#> [5,] "J"  "I"