to_frac: Convert to fractions of row or column totals

View source: R/sparse_matrix_functions.R

to_fracR Documentation

Convert to fractions of row or column totals

Description

Divides the elements of a matrix by their corresponding row or column totals. This is useful, for example, when converting a gene expression count matrix to transcripts per million (TPM).

Usage

to_frac(mat, MARGIN = 2)

Arguments

mat

A matrix. May be sparse (i.e. of class dgTMatrix, dgCMatrix or dgRMatrix).

MARGIN

The subscript to apply over. Possible values are 1 and 2. If 1, each element will be divided by its corresponding row total; if 2, its column total.

Value

A matrix of the same size and class as mat.

Examples

mat <- matrix(round(runif(100, max = 100)), 10, 10)
to_frac(mat)
to_frac(mat, MARGIN = 1)
mat[sample(1:100, 80)] <- 0
mat <- as(mat, 'dgCMatrix')
to_frac(mat)

m20ty/matkot documentation built on July 1, 2023, 8:11 p.m.