Is it possible to apply function to each cell in a DataFrame/matrix multithreadedly in R?
I'm aware of apply() but it doesn't seem to allow multithreading natively:
x <- cbind(x1 = 3, x2 = c(4:1, 2:5))
cave <- function(x, c1, c2) {
a = 1000
for (i in 1:100) { # Useless busy work
b=matrix(runif(a*a), nrow = a, ncol=a)
}
c1 + c2 * x
}
apply(x, 1, cave, c1 = 3, c2 = 4)
returns:
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
x1 15 15 15 15 15 15 15 15
x2 19 15 11 7 11 15 19 23
Instead, I would like to use more than one core to perform the operation, since the applied function may be complex. For example, one can apply a function to each cell in DataFrame multithreadedly in pandas.