PTT
Submit
Submit
選擇語言
正體中文
简体中文
PTT
R_Language
Re: [問題] 比對兩個list
作者:
CKPILOT
(新年快樂!)
2015-11-06 14:21:01
#BAD example: without memory preallocation
intersection <- names(a.list)[names(a.list) %in% names(b.list)]
result <- as.list(NULL)
for(i in intersection){
result[[i]] <- sum(table(a.list[[i]][a.list[[i]] %in% b.list[[i]]]))
}
#Fixed:
intersection <- names(a.list)[names(a.list) %in% names(b.list)]
result <- vector("list", length(intersection))
names(result) <- intersection
for(i in intersection){
result[[i]] <- sum(table(a.list[[i]][a.list[[i]] %in% b.list[[i]]]))
#cat(tracemem(result), '\n')
}
作者:
celestialgod
(天)
2015-11-06 14:25:00
建議:append一個NULL的list並非好習慣...還是先preallocate: result=vector('list', length(intersection))
#1LjDrSmd (R_Language)
作者: CKPILOT (新年快樂!)
2015-11-06 14:31:00
Thanks, it's really important for mem allocation
繼續閱讀
[問題] postscript 產生的 eps 圖檔
Chris7462
Re: [問題] 比對兩個list
celestialgod
[問題] 比對兩個list
angela79979
Re: [問題] 依照條件,計算欄位,合併欄位
celestialgod
[問題] 依照條件,計算欄位,合併欄位
JJabrams
Re: [問題] 質因數分解
showfeb
Re: [問題] 資料讀入
ror
Re: [問題] 質因數分解
taurusrob
[問題] 資料讀入
Udyr
Re: [問題] 質因數分解
celestialgod
Links
booklink
Contact Us: admin [ a t ] ucptt.com