Subset counts so that all samples have the same number of observations.

rarefy(biom, depth = NULL, seed = 0)

## Arguments

biom A matrix, simple_triplet_matrix, or BIOM object, as returned from read.biom. For matrices, the rows and columns are assumed to be the taxa and samples, respectively. The number of observations to keep, per sample. If set to NULL, a depth will be automatically selected. Samples that have fewer than this number of observations will be dropped. If called on data with non-integer abundances, values will be re-scaled to integers between 1 and depth such that they sum to depth. An integer to use for seeding the random number generator. If you need to create different random rarefactions of the same BIOM object, set this seed value to a different number each time.

## Value

A matrix, simple_triplet_matrix, or BIOM object, depending on the input object type. The type of object provided is the same type that is returned. The retained observations are randomly selected, based on a seed value derived from the BIOM object. Therefore, rarefying the same biom to the same depth will always produce the same resultant rarification.

## Examples

    library(rbiom)

infile <- system.file("extdata", "hmp50.bz2", package = "rbiom")
biom <- read.biom(infile)
range(slam::col_sums(biom$counts)) #> [1] 182 22117 biom <- rarefy(biom, depth=1000) range(slam::col_sums(biom$counts))
#> [1] 1000 1000