big_apply {bigstatsr}  R Documentation 
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). See also the corresponding vignette.
big_parallelize bigparallelr::split_parapply
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'))
# 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'))
# 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))
# 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'))