3

I know that the R package bigmemory works great in dealing with large matrices and data frames. However, I was wondering if there is any package or any ways to efficiently work with large list.

Specifically, I created a list with its elements being vectors. I have a for loop and during each iteration, multiple values were appended to a selected element in that list (a vector). At first, it runs fast, but when the iteration is over maybe 10000, it slows down gradually (one iteration takes about a second). I'm going to go through about 70000 to 80000 iterations, and the list would be so large after that.

So I was just wondering if there is something like big.list as the big.matrix in the bigmemory package that could speed up this whole process.

Thanks!

4

2 に答える 2

2

これが役立つ答えかどうかはよくわかりませんが、filehashパッケージを使用してディスク上のリストをインタラクティブに操作できます。

たとえば、ディスクデータベースを作成し、事前に割り当てられた空のリストをデータベースに割り当ててから、データベースのリストを埋める関数 (現在の時刻を取得する) を実行するコードを次に示します。

# how many items in the list?
n <- 100000
# setup database on disk
dbCreate("testDB") 
db <- dbInit("testDB")
# preallocate vector in database
db$time <- vector("list", length = n)
# run function using disk object
for(i in 1:n) db$time[[i]] <- Sys.time()

このプロセス中に RAM を使用することはほとんどありませんが、ディスク I/O が一定しているため、非常に低速です (一部のテストでは RAM で実行するよりも 2 桁遅くなります)。したがって、この方法が、大きなオブジェクトの作業を高速化するにはどうすればよいかという質問に対する適切な答えであるかどうかはわかりません。

于 2013-05-22T05:19:43.960 に答える
1

DSLパッケージが役立つかもしれません。このDListオブジェクトは、R のリストに代わるドロップインのように機能します。さらに、分散リストのような機能も提供します。

于 2016-12-06T04:09:56.250 に答える