我在 R 中有一个大型 (35000 x 3) 矩阵的列表,我想将它们组合成一个矩阵,但它的长度约为 10 亿行,并且会超过 maximum object size in R .
bigmemory包允许更大的矩阵,但 doesn't appear支持rbind
将多个矩阵放在一起。
是否有其他包或技术支持从较小的矩阵创建非常大的矩阵?
另外,在您询问之前,这不是 RAM 问题,只是 R 限制,即使在 64 位 R 上也是如此。
最佳答案
你可以用循环来实现它:
library(bigmemory)
## Reproducible example
mat <- matrix(1, 50e3, 3)
l <- list(mat)
for (i in 2:100) {
l[[i]] <- mat
}
## Solution
m <- ncol(l[[1]]) ## assuming that all have the same number of columns
n <- sum(sapply(l, nrow))
bm <- big.matrix(n, m)
offset <- 0
for (i in seq_along(l)) {
mat_i <- l[[i]]
n_i <- nrow(mat_i)
ind_i <- seq_len(n_i) + offset
bm[ind_i, ] <- mat_i
offset <- offset + n_i
}
## Verif
stopifnot(offset == n, all(bm[, 1] == 1))
关于r - 将矩阵列表组合成一个 big.matrix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50532573/