R/rotateMatrix.R

Defines functions rotate

Documented in rotate

#' Rotate a matrix 90 degrees clockwise or anti-clockwise
#'
#' @param x matrix
#' @param clockwise logical, if TRUE rotate clockwise, if FALSE rotate 
#'     anti-clockwise
#'
#' @return matrix
#' @export
#' 
rotate  <- function(x, clockwise = TRUE) {
  if (clockwise) { 
    t(apply(x, 2, rev))
  } else {
    apply(t(x), 2, rev)
  } 
}
johngodlee/JLGMisc documentation built on June 29, 2024, 9:15 p.m.