Learn R Programming

slam (version 0.1-14)

tsums: Form Ragged Row and Column Sums

Description

Form ragged row and column sums for sparse arrays (currently simple_triplet_matrix and matrix only).

Usage

row_tsums(x, INDEX, na.rm = FALSE, dims = 1, ...)
col_tsums(x, INDEX, na.rm = FALSE, dims = 1, ...)

## S3 method for class 'matrix': row_tsums(x, INDEX, na.rm = FALSE, dims = 1, \dots) ## S3 method for class 'matrix': col_tsums(x, INDEX, na.rm = FALSE, dims = 1, \dots) ## S3 method for class 'simple_triplet_matrix': row_tsums(x, INDEX, na.rm = FALSE, dims = 1, \dots) ## S3 method for class 'simple_triplet_matrix': col_tsums(x, INDEX, na.rm = FALSE, dims = 1, \dots)

Arguments

x
a sparse array containing numeric, integer, or logical values.
INDEX
a factor in the sense that as.factor(f) defines the grouping.
na.rm
logical. Should missing values (including NaN) be omitted from the calculations?
dims
currently not used for sparse arrays.
...
currently not used for sparse arrays.

Value

  • An object of the same class as x where for class simple_triplet_matrix the values are always of type double. The rownames (or colnames) are taken from INDEX.

Details

Provides fast ragged summation over the rows or columns of sparse matrices in simple_triplet-form.

See Also

simple_triplet_matrix, colSums for dense numeric arrays.

Examples

Run this code
##
x <- matrix(c(1, 0, 0, 2, 1, NA), nrow = 3)
x
s <- as.simple_triplet_matrix(x)
col_tsums(s, c(1,2,1))
z <- col_tsums(s, c(1,2,1), na.rm = TRUE)
z
## check
zz <- col_tsums(as.matrix(s), c(1,2,1), na.rm = TRUE)
identical(zz, as.matrix(z))

Run the code above in your browser using DataLab