Sum and count positive sparse entries by column group
Source:R/sparse_matrix_tools.R
sparse_group_stats.RdSum and count positive sparse entries by column group
Usage
sparse_group_stats(x, group, n_groups, transform = c("identity", "expm1"))Value
A list with dense numeric matrices sum and detected, one row
per input row and one column per group code. Input row names are preserved.
Counts omit stored and implicit zeros. An overflowing sum is Inf.
Examples
x <- Matrix::sparseMatrix(i = c(1, 2), j = c(1, 2), x = c(2, 3))
sparse_group_stats(x, group = c(2L, 1L), n_groups = 2L)
#> $sum
#> [,1] [,2]
#> [1,] 0 2
#> [2,] 3 0
#>
#> $detected
#> [,1] [,2]
#> [1,] 0 1
#> [2,] 1 0
#>