This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shiftMatrix <- function(mx, dr, dc) { | |
#Shift the matrix by dr (delta r) rows and dc columns | |
#by adding e.g. dr rows of zeros and removing dr rows from the other side | |
nr <- nrow(mx) | |
nc <- ncol(mx) | |
#If the matrix is shifted by more than its nrow or ncol, we get a matrix of zeros | |
if (abs(dr) >= nr || abs(dc) >= nc) { | |
mx <- matrix(0, nrow = nr, ncol = nc) |