[問題] Error:can't allocate vector of size Gb

看板R_Language作者 (沒有妳的我)時間6年前 (2018/11/02 18:08), 6年前編輯推噓2(2010)
留言12則, 2人參與, 6年前最新討論串1/1
[問題類型]: 程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來) [軟體熟悉度]: 入門(寫過其他程式,只是對語法不熟悉) [問題敘述]: 之前一開始用image畫圖出來之後,加上levelplot()那段指令都能畫的出colorbar,但畫 了幾次之後,執行levelplot()那段指令都會出現下圖中的錯誤訊息,且colorbar也沒跑 出來。 我上了stackoverflow查到好像有人說這是記憶體空間的問題,而我也試了在levelplot指 令前加上gc(),且從工作管理員也看到記憶體用量降到40%左右,但執行levelplot()之後 還是出現同樣的錯誤訊息,且在兩台電腦試都一樣,而我裝了ff套件之後試也還是一樣, 所以想請教各位大大這是什麼問題以及可以解決嗎(除了換電腦記憶體的容量)?? 小弟的電腦記憶體容量(RAM)為4GB。 [程式範例]: rm(list=ls()) library(ncdf4) library(data.table) TRMM_data <- "C:\\Users\\TOM\\Desktop\\R(資料庫)\\TRMM資料\\trmm_2010.nc" obs <- nc_open(TRMM_data) lon <- ncvar_get(obs,"lon") lat <- ncvar_get(obs,"lat") time <- ncvar_get(obs,"time") precip <- ncvar_get(obs,"r") time <- matrix(seq(as.Date("2010-01-01"), as.Date("2010-12-31"),1)) precip1 <- matrix(NA_real_,1440,400) for(i in c(1:1440)){ for(j in c(1:400)){ precip1[i,j] <- mean(precip[i,j,time=(1:31)]) } } library(RColorBrewer) image(lon,lat,precip1,col=rev(brewer.pal(10,"RdBu"))) gc() library(lattice) grid <- expand.grid(lon=lon, lat=lat) cutpts <- c(0,5,10,15,20,25,30,35,40,45,50) levelplot(precip ~ lon * lat, data=grid, at=cutpts, cuts=11, pretty=T, col.regions=(rev(brewer.pal(10,"RdBu")))) library(sp) library(maps) map(database='world2',add= TRUE) [環境敘述]: https://imgur.com/qdHINqH
[關鍵字]: 記憶體空間 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.231.180.201 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1541153336.A.8F9.html

11/02 19:08, 6年前 , 1F
先確定是對precip還是precip1畫圖吧
11/02 19:08, 1F

11/03 00:08, 6年前 , 2F
precip1,andrew大,這篇是你在問我之前寫的XD
11/03 00:08, 2F
※ 編輯: AndrewShi (180.217.184.236), 11/03/2018 00:09:43

11/03 01:17, 6年前 , 3F
所以畫圖時你用錯物件了。
11/03 01:17, 3F

11/03 01:32, 6年前 , 4F
我知道了,precip要改成precip1,抱歉andrew大我又犯
11/03 01:32, 4F

11/03 01:32, 6年前 , 5F
傻了XD
11/03 01:32, 5F

11/03 01:59, 6年前 , 6F
不過andrew大~我之前在處理這種netcdf(nc)檔的時候,
11/03 01:59, 6F

11/03 01:59, 6年前 , 7F
像是讀取降雨的變數,如果我的一個nc檔案是10年(或以上
11/03 01:59, 7F

11/03 01:59, 6年前 , 8F
)的降雨資料的話,在讀取降雨這個變數時好像也會出現這
11/03 01:59, 8F

11/03 01:59, 6年前 , 9F
個錯誤訊息耶,這樣的話有解決辦法嗎??
11/03 01:59, 9F

11/03 02:54, 6年前 , 10F
不確定也。可以發一篇新文問。
11/03 02:54, 10F

11/03 17:13, 6年前 , 11F
恩恩,我之後處理資料如果有碰到同樣問題再發文問問看
11/03 17:13, 11F

11/03 17:13, 6年前 , 12F
11/03 17:13, 12F
文章代碼(AID): #1Rt28uZv (R_Language)
文章代碼(AID): #1Rt28uZv (R_Language)