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