Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple working example of ddply() in parallel on Windows

Tags:

I've been searching around for a simple working example of using ddply() in parallel. I've installed the "foreach" package, but when I call ddply( .parallel = TRUE) I get a warning that "No parallel backend registered")

Can someone provide a simple working example of using ddply in parallel?

like image 426
SFun28 Avatar asked Jul 21 '11 17:07

SFun28


1 Answers

Here's a simple working example:

> df <- data.frame(val=1:10, ind=c(rep(2, 5), rep(3, 5))) > library(doSNOW) > registerDoSNOW(makeCluster(2, type = "SOCK")) > system.time(print(ddply(df, .(ind), function(x) { Sys.sleep(2); sum(x) }, .parallel=FALSE)))   ind V1 1   2 25 2   3 55    user  system elapsed     0.00    0.00    4.01  > system.time(print(ddply(df, .(ind), function(x) { Sys.sleep(2); sum(x) }, .parallel=TRUE)))   ind V1 1   2 25 2   3 55    user  system elapsed     0.02    0.00    2.02  
like image 160
Shane Avatar answered Sep 24 '22 01:09

Shane