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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With