downsample_matrix {tglkmeans} | R Documentation |
Downsample the columns of a matrix to a target number
Description
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.
Usage
downsample_matrix(
mat,
target_n = NULL,
target_q = NULL,
seed = NULL,
remove_columns = FALSE
)
Arguments
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) |
Value
The downsampled matrix
Examples
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)
[Package tglkmeans version 0.5.5 Index]