多核和数据表 [英] multicore and data.table in R
本文介绍了多核和数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用多核
函数并行
与 data.table
,我不能真正想出正确的方法来做到这一点。代码:
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
我想在这里调用 collect()
parallel
对象。
I would like to call collect()
on this but these are no longer parallel
objects. How should one do this?
推荐答案
我认为这是沿着你想要的方式:
I think this is along the lines of what you want:
collect(dtb[, list(jobs = list(parallel(a+1))), by = b][, jobs])
之所以没有 parallel
无法运行 collect
是因为您正在将它们转换为 列表
将它们存储在列表中,这是我上面做的。
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.
这篇关于多核和数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文