我有一个矩阵B.
dim(B)
> 3025 3025
当我尝试使用此矩阵来创建图形对象时,我收到了错误:
library(igraph)
g <- graph.adjacency(B, weighted=TRUE, mode="undirected", diag=FALSE)
# Error in .Call("R_igraph_weighted_adjacency", adjmatrix,
# as.numeric(mode), :
# At vector.pmt:439 : cannot reserve space for vector, Out of memory
错误的原因是什么?这是R还是我的电脑的限制?
> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows Vista (build 6001) Service Pack 1
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] igraph_1.0.1
更新(在@Gabor评论之后)。 我试图重现错误。我用过:
B <- matrix(runif(3025*3025, 0, 10), nc = 3025)
#Error: cannot allocate vector of size 69.8 Mb
g <- graph.adjacency(B, weighted=TRUE, mode="undirected", diag=FALSE)
object.size(B)
#73423056 bytes
object.size(g)
#395900 bytes
但错误有所不同。错误发生在库(igraph)的调用函数之前。然后我写了
B<-c()
>B
NULL
B <- matrix(runif(3025*3025, 0, 10), nc = 3025)
g <- graph.adjacency(B, weighted=TRUE, mode="undirected", diag=FALSE)
Error in .Call("R_igraph_weighted_adjacency", adjmatrix, as.numeric(mode), :
At vector.pmt:439 : cannot reserve space for vector, Out of memory
dim(B)
#[1] 3025 3025
object.size(B)
#73205112 bytes
object.size(g)
#395900 bytes
答案 0 :(得分:2)
错误来自library(igraph)
,始终来自graph.adjacency
。
igraph针对稀疏图进行了优化,您的图是完整的图,因此这并不理想。
最重要的是,您需要更多内存。此图表需要大约300 MB的内存,显然你没有。
如果您未能创建object.size
,我不确定如何致电g
。