R/split.matrix.R

Defines functions split.matrix

split.matrix <- function(mat, r=NULL, c=NULL){

  if(is.null(r)){
    r <- nrow(mat)
  }
  if(is.null(c)){
    c <- ncol(mat)
  }
  
  rg <- (row(mat)-1)%/%r+1
  cg <- (col(mat)-1)%/%c+1
  rci <- (rg-1)*max(cg) + cg
  N <- prod(dim(mat))/r/c
  cv <- lapply(1:N, function(x) mat[rci==x])
  return(cv)
}

Try the ThurMod package in your browser

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

ThurMod documentation built on Sept. 19, 2023, 5:07 p.m.