I have a matrix with the dimension of 100 million records and 100 columns.
Now I want to multiply that matrix by rowwise.
My sample code for matrix multiplic
If you have a matrix that is too large to fit in memory, you can use package bigstatsr (disclaimer: I'm the author) to use data stored on your disk (instead of the RAM). Using function big_apply enables you to apply standard R functions on data blocks (and to combine them).
library(bigstatsr)
fbm <- FBM(10e6, 100)
# inialize with random numbers
system.time(
big_apply(fbm, a.FUN = function(X, ind) {
print(min(ind))
X[, ind] <- rnorm(nrow(X) * length(ind))
NULL
}, a.combine = 'c')
) # 78 sec
# compute row prods, possibly in parallel
system.time(
prods <- big_apply(fbm, a.FUN = function(X, ind) {
print(min(ind))
matrixStats::rowProds(X[ind, ])
}, a.combine = 'c', ind = rows_along(fbm),
block.size = 100e3, ncores = nb_cores())
) # 22 sec with 1 core and 18 sec with 6 cores