Re: [問題] 比對兩個list
#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')
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.193.135.208
※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1446790865.A.50F.html
※ 編輯: CKPILOT (123.193.135.208), 11/06/2015 14:22:23
→
11/06 14:25, , 1F
11/06 14:25, 1F
→
11/06 14:25, , 2F
11/06 14:25, 2F
→
11/06 14:25, , 3F
11/06 14:25, 3F
→
11/06 14:27, , 4F
11/06 14:27, 4F
→
11/06 14:31, , 5F
11/06 14:31, 5F
※ 編輯: CKPILOT (123.193.135.208), 11/06/2015 15:19:20
※ 編輯: CKPILOT (123.193.135.208), 11/06/2015 15:20:28
討論串 (同標題文章)
完整討論串 (本文為第 3 之 3 篇):
R_Language 近期熱門文章
PTT數位生活區 即時熱門文章
27
162