Let\'s make a replicable example:
This is my initial matrix
d<- matrix(1:80,,5) d [,1] [,2] [,3] [,4] [,5] [1,] 1 17 33 49 65 [2,
Yet another approach:
n = 4 matrix(aperm(array(d, c(n, nrow(d)/n, ncol(d))), c(1, 3, 2)), ncol = nrow(d)/n)