R/transform_M.R

Defines functions transform_M

Documented in transform_M

#' Apply row left-right flips and column up-down flips to a matrix
#'
#' @param M Initial matrix
#' @param L1 Vector of row indices (1‑based) to be left-right flipped
#' @param L2 Vector of column indices (1‑based) to be up-down flipped
#'
#' @return Transformed matrix
#' @export
#'
transform_M <- function(M, L1, L2) {
  M1 <- M
  # Row left-right flip
  for (r in L1) {
    M1[r, ] <- rev(M1[r, ])
  }
  # Column up-down flip
  for (c in L2) {
    M1[, c] <- rev(M1[, c])
  }
  M1
}

Try the YangHuiMagic package in your browser

Any scripts or data that you put into this service are public.

YangHuiMagic documentation built on March 23, 2026, 5:07 p.m.