multicore and data.table in R

人走茶凉 提交于 2020-01-12 05:33:07

问题


I am attempting to use multicore function parallel with data.table and am unable to quite come up with the right way to do this. Code:

require(multicore)
require(data.table)
dtb = data.table(a=1:10, b=1:2)
x = dtb[,parallel(a+1),by=b]

> x
   b   pid fd
1: 1 12243  3
2: 1 12243  6
3: 2 12247  4
4: 2 12247  8

I would like to call collect() on this but these are no longer parallel objects. How should one do this?


回答1:


I think this is along the lines of what you want:

collect(dtb[, list(jobs = list(parallel(a+1))), by = b][, jobs])

The reason you didn't have parallel objects any more and couldn't run a collect is because you were converting them to a list, instead of storing them in a list, which is what I did above.



来源:https://stackoverflow.com/questions/14697670/multicore-and-data-table-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!