I have a very big data.frameone that I want to apply a rather complicated function to computing a new column. I want to do this in parallel. This is similar to the question posted over r listserve , but the first answer is incorrect and the second is useless.
I got everything that was found out thanks to the package parallel, except how to return the output to the data frame. Here's the MWE, which shows what I have:
library(parallel)
data <- data.frame(a = rnorm(200), b = rnorm(200),
group = sample(letters, 200, replace = TRUE))
datagroup <- split(data, factor(data$group))
options(mc.cores = detectCores())
output <- mclapply(datagroup, function(x) x$a*x$b)
Result in outputis a list of number vectors. I need them in the column that I can add to data. I was looking through the lines do.call(cbind, ...), but I have two lists with the same name, and not one list that I am joining. melt(output)gets one vector, but its lines do not match data.
source
share