我有一个包含 1,344 个唯一字符串的向量 x。我想生成一个矩阵,它为我提供所有可能的三个值组,无论顺序如何,并将其导出到 csv。
我在带有 64 位 Ubuntu 的 m1.large 实例上的 EC2 上运行 R。使用 combn(x, 3) 时出现内存不足错误:
Error: cannot allocate vector of size 9.0 Gb
结果矩阵的大小为 C1344,3 = 403,716,544 行和三列 - 这是 combn() 函数结果的转置。
我想使用 bigmemory 包创建一个支持 big.matrix 的文件,这样我就可以分配 combn() 函数的结果。我可以创建一个预先分配的大矩阵:
library(bigmemory)
x <- as.character(1:1344)
combos <- 403716544
test <- filebacked.big.matrix(nrow = combos, ncol = 3,
init = 0, backingfile = "test.matrix")
但是当我尝试分配值时,test <- combn(x, 3)
我仍然得到相同的结果:Error: cannot allocate vector of size 9.0 Gb
我什至尝试强制执行结果,combn(x,3)
但我认为因为 combn() 函数返回错误,所以 big.matrix 函数也不起作用。
test <- as.big.matrix(matrix(combn(x, 3)), backingfile = "abc")
Error: cannot allocate vector of size 9.0 Gb
Error in as.big.matrix(matrix(combn(x, 3)), backingfile = "abc") :
error in evaluating the argument 'x' in selecting a method for function 'as.big.matrix'
有没有办法将这两个功能结合在一起以获得我需要的东西?有没有其他方法可以实现这一目标?谢谢。