big_apply.Rd
A SplitApplyCombine strategy to apply common R functions to a Filebacked Big Matrix.
big_apply( X, a.FUN, a.combine = NULL, ind = cols_along(X), ncores = 1, block.size = block_size(nrow(X), ncores), ... )
X  An object of class FBM. 

a.FUN  The function to be applied to each subset matrix.
It must take a Filebacked Big Matrix as first argument and

a.combine  Function to combine the results with 
ind  Initial vector of subsetting indices. Default is the vector of all column indices. 
ncores  Number of cores used. Default doesn't use parallelism. You may use nb_cores. 
block.size  Maximum number of columns (or rows, depending on how you
use 
...  Extra arguments to be passed to 
This function splits indices in parts, then apply a given function to each subset matrix and finally combine the results. If parallelization is used, this function splits indices in parts for parallelization, then split again them on each core, apply a given function to each part and finally combine the results (on each cluster and then from each cluster).
X < big_attachExtdata() # get the means of each column colMeans_sub < function(X, ind) colMeans(X[, ind]) str(colmeans < big_apply(X, a.FUN = colMeans_sub, a.combine = 'c'))#> num [1:4542] 1.32 1.59 1.53 1.63 1.09 ...# get the norms of each column colNorms_sub < function(X, ind) sqrt(colSums(X[, ind]^2)) str(colnorms < big_apply(X, colNorms_sub, a.combine = 'c'))#> num [1:4542] 33.6 38.4 37.5 39.2 29.6 ...# get the sums of each row # split along rows: need to change the "complete" `ind` parameter str(rowsums < big_apply(X, a.FUN = function(X, ind) rowSums(X[ind, ]), ind = rows_along(X), a.combine = 'c', block.size = 100))#> num [1:517] 6243 6168 6242 6249 6212 ...# it is usually preferred to split along columns # because matrices are stored by column. str(rowsums2 < big_apply(X, a.FUN = function(X, ind) rowSums(X[, ind]), a.combine = 'plus'))#> num [1:517] 6243 6168 6242 6249 6212 ...