downsample_matrix | R Documentation |
This function takes a matrix and downsamples it to a target number of samples. It uses a random seed for reproducibility and allows for removing columns with small sums.
downsample_matrix(
mat,
target_n = NULL,
target_q = NULL,
seed = NULL,
remove_columns = FALSE
)
mat |
An integer matrix to be downsampled. Can be a matrix or sparse matrix (dgCMatrix).
If the matrix contains NAs, the function will run significantly slower. Values that are
not integers will be coerced to integers using |
target_n |
The target number of samples to downsample to. |
target_q |
A target quantile of sums to downsample to. Only one of 'target_n' or 'target_q' can be provided. |
seed |
The random seed for reproducibility (default is NULL) |
remove_columns |
Logical indicating whether to remove columns with small sums (default is FALSE) |
The downsampled matrix
mat <- matrix(1:12, nrow = 4)
downsample_matrix(mat, 2)
# Remove columns with small sums
downsample_matrix(mat, 12, remove_columns = TRUE)
# sparse matrix
mat_sparse <- Matrix::Matrix(mat, sparse = TRUE)
downsample_matrix(mat_sparse, 2)
# with a quantile
downsample_matrix(mat, target_q = 0.5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.