rotate_matrix: Rotate a Matrix by 90 Degrees

View source: R/CodeAndRoll2.R

rotate_matrixR Documentation

Rotate a Matrix by 90 Degrees

Description

Rotates a given numeric matrix 90 degrees in a specified direction. The rotation can be either clockwise or counterclockwise, determined by the clockwise parameter.

Usage

rotate_matrix(x, clockwise = TRUE)

Arguments

x

A numeric matrix that is to be rotated.

clockwise

Logical; if TRUE (default), rotates the matrix 90 degrees clockwise.

Value

A numeric matrix rotated 90 degrees in the specified direction.

Examples

# Define a 3x3 matrix
matrix_original <- matrix(1:9, nrow = 3)

# Rotate the matrix clockwise
rotated_clockwise <- rotate(matrix_original, TRUE)

# Rotate the matrix counterclockwise
rotated_counterclockwise <- rotate(matrix_original, FALSE)


vertesy/CodeAndRoll2 documentation built on Nov. 20, 2024, 5:23 a.m.