在向量化一些仿真代碼的過程中,我遇到了內存問題。我正在Windows XP下使用32位R版本2.15.0(通過RStudio版本0.96.122)。我的機器有3.46 GB的RAM。> sessionInfo()R version 2.15.0 (2012-03-30)Platform: i386-pc-mingw32/i386 (32-bit)locale:[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 [3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C [5] LC_TIME=English_United Kingdom.1252 attached base packages:[1] stats graphics grDevices utils datasets methods base other attached packages:[1] Matrix_1.0-6 lattice_0.20-6 MASS_7.3-18 loaded via a namespace (and not attached):[1] grid_2.15.0 tools_2.15.0這是問題的最小示例:> memory.limit(3000)[1] 3000> rm(list = ls())> gc() used (Mb) gc trigger (Mb) max used (Mb)Ncells 1069761 28.6 1710298 45.7 1710298 45.7Vcells 901466 6.9 21692001 165.5 173386187 1322.9> N <- 894993> library(MASS)> sims <- mvrnorm(n = N, mu = rep(0, 11), Sigma = diag(nrow = 11))> sims <- mvrnorm(n = N + 1, mu = rep(0, 11), Sigma = diag(nrow = 11))Error: cannot allocate vector of size 75.1 Mb(在我的應用程序中,協方差矩陣Sigma不是對角線,但是無論哪種方式,我都會得到相同的誤差。)我花了整個下午閱讀有關R中的內存分配問題的信息(包括here,here和here)。從我讀過的書中,我得到的印象是,這與RAM本身無關,而與連續地址空間有關。不過,對我來說75.1Mb似乎很小。如果您有任何想法或建議,我將不勝感激。r 內存管理
3 回答

月關寶盒
TA貢獻1772條經驗 獲得超5個贊
使用柵格數據包時,我也有同樣的警告。
> my_mask[my_mask[] != 1] <- NA
Error: cannot allocate vector of size 5.4 Gb
該解決方案非常簡單,包括增加R的存儲容量,此處為代碼行:
##To know the current storage capacity
> memory.limit()
[1] 8103
## To increase the storage capacity
> memory.limit(size=56000)
[1] 56000
## I did this to increase my storage capacity to 7GB
希望這將幫助您解決問題
- 3 回答
- 0 關注
- 3138 瀏覽
添加回答
舉報
0/150
提交
取消