Learn R Programming

rbiom (version 2.2.0)

rarefy_cols: Transform a counts matrix.

Description

Rarefaction subset counts so that all samples have the same number of observations. Rescaling rows or cols scales the matrix values so that row sums or column sums equal 1.

Usage

rarefy_cols(mtx, depth = 0.1, n = NULL, seed = 0L, cpus = NULL)

rescale_cols(mtx)

rescale_rows(mtx)

Value

The rarefied or rescaled matrix.

Arguments

mtx

A matrix-like object.

depth

How many observations to keep per sample. When 0 < depth < 1, it is taken as the minimum percentage of the dataset's observations to keep. Ignored when n is specified. Default: 0.1

n

The number of samples to keep. When 0 < n < 1, it is taken as the percentage of samples to keep. If negative, that number or percentage of samples is dropped. If 0, all samples are kept. If NULL, depth is used instead. Default: NULL

seed

A positive integer to use for seeding the random number generator. If you need to create different random rarefactions of the same matrix, set this seed value to a different number each time.

cpus

The number of CPUs to use. Set to NULL to use all available, or to 1 to disable parallel processing. Default: NULL

See Also

Other rarefaction: rare_corrplot(), rare_multiplot(), rare_stacked(), rarefy(), sample_sums()

Other transformations: modify_metadata, rarefy(), slice_metadata, subset(), with()

Examples

Run this code
    library(rbiom)
    
    # rarefy_cols --------------------------------------
    biom <- hmp50$clone()
    sample_sums(biom) %>% head(10)

    biom$counts %<>% rarefy_cols(depth=1000)
    sample_sums(biom) %>% head(10)
    
    
    # rescaling ----------------------------------------
    mtx <- matrix(sample(1:20), nrow=4)
    mtx
    
    rowSums(mtx)
    rowSums(rescale_rows(mtx))
    
    colSums(mtx)
    colSums(rescale_cols(mtx))

Run the code above in your browser using DataLab