View source: R/sparse_matrix_functions.R
log_transform | R Documentation |
Log transforms a matrix after adding 1, or the reverse, exponentiates the matrix and then subtracts 1. In the case of sparse matrices (class dgTMatrix
, dgCMatrix
or dgRMatrix
), only the non-zero elements are transformed. This is faster than manually adding or subtracting 1, as it retains the sparse matrix class.
log_transform(mat, base = 2, reverse = FALSE)
mat |
A matrix. May be sparse (i.e. of class |
base |
A positive number: the base with respect to which the logarithms are computed. Default: 2. |
reverse |
If |
A matrix of the same size and class as mat
.
mat <- matrix(round(runif(100, max = 100)), 10, 10)
log_transform(mat)
log_transform(log_transform(mat), reverse = TRUE)
mat[sample(1:100, 80)] <- 0
mat <- as(mat, 'dgCMatrix')
log_transform(mat)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.