collapse_counts: Collapse counts based on multiple categorical metadata...

View source: R/pseudobulk.R

collapse_countsR Documentation

Collapse counts based on multiple categorical metadata columns

Description

Collapse counts based on multiple categorical metadata columns

Usage

collapse_counts(
  counts_mat,
  meta_data,
  varnames,
  min_cells_per_group = 0,
  keep_n = FALSE,
  how = c("sum", "mean")[1]
)

Arguments

counts_mat

counts matrix where columns represent cells and rows represent features

meta_data

data.frame containing cell metadata

varnames

subset of 'meta_data' column names

min_cells_per_group

minimum cells to keep collapsed group

keep_n

keep or drop the 'N' column containing the number of cells in each group. Default is 'FALSE'

how

method of collapsing counts from groups. 'sum' or 'mean'

Examples

m <- matrix(sample.int(8, 100*500, replace=TRUE), nrow=100, ncol=500)
rownames(m) <- paste0("G", 1:100)
colnames(m) <- paste0("C", 1:500)
md1 <- sample(c("a", "b"), 500, replace=TRUE)
md2 <- sample(c("c", "d"), 500, replace=TRUE)
df <- data.frame(md1, md2)
data_collapsed <- collapse_counts(m, df, c("md1", "md2"))
head(data_collapsed$counts_mat)


immunogenomics/presto documentation built on March 26, 2024, 8:18 a.m.