min_scalar: Take minumum with a global constant
min_by_row: Take the minimum with a per-row constant
min_by_col: Take the minimum with a per-col constant
Details
Take the minimum value of a matrix with a per-row, per-col, or global constant. This constant must be >0 to preserve sparsity of the matrix. This has the effect of capping the maximum value in the matrix.
Examples
set.seed(12345)
mat <- matrix(rpois(40, lambda = 5), nrow = 4)
rownames(mat) <- paste0("gene", 1:4)
mat <- mat %>% as("dgCMatrix")
mat
#> 4 x 10 sparse Matrix of class "dgCMatrix"
#>
#> gene1 6 5 6 6 4 5 6 3 3 8
#> gene2 8 3 11 . 4 4 4 5 6 8
#> gene3 6 4 1 4 3 9 6 7 4 6
#> gene4 8 5 3 5 9 6 5 . 4 3
mat <- mat %>% as("IterableMatrix")
#######################################################################
## min_scalar() example
#######################################################################
min_scalar(mat, 4) %>% as("dgCMatrix")
#> 4 x 10 sparse Matrix of class "dgCMatrix"
#>
#> gene1 4 4 4 4 4 4 4 3 3 4
#> gene2 4 3 4 . 4 4 4 4 4 4
#> gene3 4 4 1 4 3 4 4 4 4 4
#> gene4 4 4 3 4 4 4 4 . 4 3
#######################################################################
## min_by_row() example
#######################################################################
min_by_row(mat, 1:4) %>% as("dgCMatrix")
#> 4 x 10 sparse Matrix of class "dgCMatrix"
#>
#> gene1 1 1 1 1 1 1 1 1 1 1
#> gene2 2 2 2 . 2 2 2 2 2 2
#> gene3 3 3 1 3 3 3 3 3 3 3
#> gene4 4 4 3 4 4 4 4 . 4 3
#######################################################################
## min_by_col() example
#######################################################################
min_by_col(mat, 1:10) %>% as("dgCMatrix")
#> 4 x 10 sparse Matrix of class "dgCMatrix"
#>
#> gene1 1 2 3 4 4 5 6 3 3 8
#> gene2 1 2 3 . 4 4 4 5 6 8
#> gene3 1 2 1 4 3 6 6 7 4 6
#> gene4 1 2 3 4 5 6 5 . 4 3