rarefy: Rarefy (subsample) a matrix

View source: R/rarefy.R

rarefyR Documentation

Rarefy (subsample) a matrix

Description

This function will randomly subsample counts from rows of the input matrix such that the colSums all have even depth.

Usage

rarefy(x, depth)

Arguments

x

numeric matrix or data.frame that can be converted to a numeric matrix. Samples in columns features in rows.

depth

desired sampling depth applied to each library.

Examples

set.seed(123)
m <- matrix(
  sample.int(100),
  nrow = 10,
  dimnames = list(
    Gene = paste0("gene.", 1:10),
    Sample = paste0("sample.", 1:10)
  )
)

colSums(m)

rarefied <- rarefy(m, depth = 100)
colSums(rarefied)

jcalendo/coriell documentation built on March 5, 2025, 5:42 a.m.