install.packages("rbenchmark") install.packages("snow") library (MASS) library(tidyverse) library (rbenchmark) library(snow) #An example of tapply and summarize & group tapply (Cars93$Price, Cars93$Manufacturer , mean) summarize(group_by(Cars93,Manufacturer),mean=mean(Price)) #Examples of using snow library install.packages("snow") library(snow) #First example z = list(1,1,1,1,1,1,1) system.time(sapply (z, Sys.sleep)) cl <-makeCluster (7) system.time(parSapply (cl, z, Sys.sleep)) stopCluster (cl) #Second example z = rexp(6000000, 6) z = list(z, z, z, z, z, z, z, z) cl <-makeCluster (8) benchmark(parSapply (cl, z, function(val){2^val + 2^val + 2^val}), sapply (z, function(val){2^val + 2^val + 2^val}),replications = 5) stopCluster (cl) #Third example z = rexp(1000000, 8) k =rexp(6000000, 8) z = list(z, z, z, k, z, z, z, z) cl <-makeCluster (8) benchmark(clusterApplyLB(cl,c(z,z,z,z), function(val){(2^val + 2^val + 2^val)}),lapply(c(z,z,z,z), function(val){2^val + 2^val + 2^val}), parLapply (cl, c(z,z,z,z), function(val){(2^val + 2^val + 2^val)}),replications = 5) stopCluster (cl) #Using fork with parallel library(parallel) z = rexp(6000000, 6) z = list(z, z, z, z, z, z, z, z) cl <- makeForkCluster(nnodes =8) benchmark(parSapply (cl, z, function(val){2^val + 2^val + 2^val}), sapply (z, function(val){2^val + 2^val + 2^val}),replications = 2) stopCluster (cl) #do.call command A <- c(2,2,2,2) f=c("mean","sum") do.call(f[1], list(A)) do.call(f[2], list(A))