Here's a sample input data, a simplified function.
require(data.table)
sampleDT <- data.table(c1 = c(1,2,3), c2 = c(4,5,6))
print(sampleDT)
c1 c2
1: 1 4
2: 2 5
3: 3 6
testF <- function(x = NULL, y = NULL) {
return(list(x+y,x))
}
resultCol <- c("r1","r2")
sampleDT[, (resultCol) := testF(c1,c2), by = seq(nrow(sampleDT))]
print(sampleDT)
c1 c2 r1 r2
1: 1 4 5 1
2: 2 5 7 2
3: 3 6 9 3
The actual function can't be vectorized easily, and it returns a 1*n list.
I'm looking for a parallel solution for this by-row & row-wise operation. Also if there're multiple ways of constructing a parallel process, which one is the speed optimized?
Please leave some sample codes, because I'm not familiar with the syntax (e.g. foreach, mclapply, etc.)