I have a function
function1 <- function(df1, df2, int1, int2, char1) { ... return(newDataFrame) }
which has 5 inputs: the first 2 are data frames, then I have two integers and a string. The function returns a new data frame.
So far, I have performed this function 8 times in a row:
newDataFrame1 <- function1(df1, df2, 1, 1, "someString") newDataFrame2 <- function1(df1, df2, 2, 0, "someString") newDataFrame3 <- function1(df1, df2, 3, 0, "someString") newDataFrame4 <- function1(df1, df2, 4, 0, "someString") newDataFrame5 <- function1(df1, df2, 5, 0, "someString") newDataFrame6 <- function1(df1, df2, 6, 0, "someString") newDataFrame7 <- function1(df1, df2, 7, 0, "someString") newDataFrame8 <- function1(df1, df2, 8, 0, "someString")
and in the end I combine the results using rbind ():
newDataFrameTot <- rbind(newDataFrame1, newDataFrame2, newDataFrame3, newDataFrame4, newDataFrame5, newDataFrame6, newDataFrame7, newDataFrame8)
I wanted to run this in parallel using the library (in parallel), but I cannot figure out how to do this. I'm trying to:
cluster <- makeCluster(detectCores()) result <- clusterApply(cluster,1:8,function1) newDataFrameTot <- do.call(rbind,result)
but this does not work if my function1 () function does not have only one parameter, which I execute from 1 to 8. But this is not my business, since I need to pass 5 inputs. How can I do this work in parallel?