https://github.com/cran/pracma
Tip revision: c79a04b5074656b36e591191eb8137b70a349932 authored by Hans W. Borchers on 30 June 2014, 00:00:00 UTC
version 1.7.0
version 1.7.0
Tip revision: c79a04b
circshift.R
circshift <- function(a, sz) {
if (is.null(a)) return(a)
if (is.vector(a) && length(sz) == 1) {
n <- length(a)
s <- sz %% n
a <- a[(1:n-s-1) %% n + 1]
} else if (is.matrix(a) && length(sz) == 2) {
n <- nrow(a); m <- ncol(a)
s1 <- sz[1] %% n
s2 <- sz[2] %% m
a <- a[(1:n-s1-1) %% n + 1, (1:m-s2-1) %% m + 1]
} else
stop("Length of 'sz' must be equal to the no. of dimensions of 'a'.")
return(a)
}