Ich ziehe diese Array-Dimensionen für die Verwendung. Sie können dann eine split
Methode für Matrizen definieren:
split.matrix <- function(x, rslice = 1, cslice = 1) {
if (ncol(x) %% cslice) stop("cslice not divisor of number of columns")
if (nrow(x) %% rslice) stop("rslice not divisor of number of rows")
x <- t(x)
dim(x) <- c(dim(x)[1],
dim(x)[2]/rslice,
rslice)
x <- lapply(seq_len(rslice), function(k, a) t(a[,,k]), a = x)
if (cslice > 1) {
x <- lapply(x, function(y, k) {
dim(y) <- c(dim(y)[1],
dim(y)[2]/k,
k)
y <- lapply(seq_len(k), function(k, a) a[,,k], a = y)
y
}, k = cslice)
}
if(length(x) == 1L) x <- x[[1]]
x
}
split(long.matrix, 1, 3)
#[[1]]
# [,1] [,2]
#[1,] 1 3
#[2,] 2 4
#
#[[2]]
# [,1] [,2]
#[1,] 1 3
#[2,] 2 4
#
#[[3]]
# [,1] [,2]
#[1,] 1 3
#[2,] 2 4
split(long.matrix, 1, 1)
# [,1] [,2] [,3] [,4] [,5] [,6]
#[1,] 1 3 1 3 1 3
#[2,] 2 4 2 4 2 4
split(long.matrix, 2, 1)
#[[1]]
# [,1] [,2] [,3] [,4] [,5] [,6]
#[1,] 1 3 1 3 1 3
#
#[[2]]
# [,1] [,2] [,3] [,4] [,5] [,6]
#[1,] 2 4 2 4 2 4
split(long.matrix, 2, 3)
#[[1]]
#[[1]][[1]]
#[1] 1 3
#
#[[1]][[2]]
#[1] 1 3
#
#[[1]][[3]]
#[1] 1 3
#
#
#[[2]]
#[[2]][[1]]
#[1] 2 4
#
#[[2]][[2]]
#[1] 2 4
#
#[[2]][[3]]
#[1] 2 4
Ganz in der Nähe http://stackoverflow.com/questions/37145863/splitting-a-dataframe-into-equal-parts –