r - 将矩阵列表组合成一个 big.matrix

标签 r matrix r-bigmemory

我在 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/

相关文章:

r - 如何将 ggplot 对象向量传递给 grid.arrange 函数?

r - 删除任何重复项及其对

r - 根据函数R中的dot dot dot获取变量参数的名称(deparse)

python - 如何在 python 中将稀疏字典转换为 scipy.sparse 矩阵?

r - 使用大矩阵操作

r - bigmemory 和带有文件支持的 friend 的示例

r - IBrokers 历史指数数据

matrix - 计算变换椭圆的 AABB

r - 如何将 2.8 GB gzipped (40 GB TSV) 文件批量读取到 R 中?

tsql - 如何在 SQL Server 中转置上三角矩阵