x <- diag(5)
f <- rep(1:2, c(2,3))
split(x, f, margin=1) # Split rows.
split(x, f, margin=2) # Split columns.
# This is similar to how data frames are split:
stopifnot(identical(split(x, f, margin=1),
lapply(lapply(split(as.data.frame(x), f), as.matrix), unname)))
Run the code above in your browser using DataLab