Skip to content

Instantly share code, notes, and snippets.

@jeffreyhanson
Last active September 8, 2015 04:41
Show Gist options
  • Save jeffreyhanson/181313ea9aed85f32975 to your computer and use it in GitHub Desktop.
Save jeffreyhanson/181313ea9aed85f32975 to your computer and use it in GitHub Desktop.
library(snow)
library(plyr)
library(doSNOW)
library(compiler)
data(mtcars)
ratio=cmpfun(
function(x, w) {
return(mean((x$mpg * w) / (x$wt * w)))
}
)
clust=makeCluster(4, "SOCK")
clusterEvalQ(clust, {library(boot)})
clusterExport(clust, c("ratio", "mtcars"))
registerDoSNOW(clust)
result=llply(
seq_len(10),
.parallel=TRUE,
.fun=function(i) {
return(boot(data=mtcars, statistic=ratio, 1))
}
)
clust=stopCluster(clust)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment