Sample Cells by Cell Type with Minimum Representation
Source:R/sample_cells_by_type.R
SampleCellsByType.RdThis function samples a specified total number of cells from a metadata table, ensuring that each cell type is represented by at least a minimum number of cells.
Examples
meta <- data.frame(
cell_id = paste0("cell", 1:10000),
cell_type = sample(c("T", "B", "Mac"), 10000, replace = TRUE)
)
set.seed(42)
sampled <- sampleCellsByType(meta,
n_total_cells = 1000,
min_per_type = 50
)