Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

apply

Apply Functions Over Sparse Matrix Margins


Description

Apply functions to (the cross-pairs of) the rows or columns of a sparse matrix.

Usage

rowapply_simple_triplet_matrix(x, FUN, ...)
colapply_simple_triplet_matrix(x, FUN, ...)

crossapply_simple_triplet_matrix(x, y = NULL, FUN, ...) 
tcrossapply_simple_triplet_matrix(x, y = NULL, FUN, ...)

Arguments

x, y

a matrix in simple_triplet_matrix-form or, one of x and y, of class matrix.

FUN

the name of the function to be applied.

...

optional arguments to FUN.

Details

colapply_simple_triplet_matrix temporarily expands each column of x to dense vector representation and applies the function specified in FUN.

crossapply_simple_triplet_matrix temporarily expands each cross-pair of columns of x (and y) to dense vector representation and applies the function specified in FUN.

Note that if y = NULL then only the entries in the lower triangle and the diagonal are computed, assuming that FUN is symmetric.

Value

A vector (matrix) of length (dimensionality) of the margin(s) used. The type depends on the result of FUN.

Note that the result of colapply_simple_triplet_matrix is never simplified to matrix.

Author(s)

Christian Buchta

See Also

apply for dense-on-dense computations.

Examples

## 
x <- matrix(c(1, 0, 0, 2, 1, 0), nrow = 3, 
    dimnames = list(1:3, LETTERS[1:2]))
x
s <- as.simple_triplet_matrix(x)
colapply_simple_triplet_matrix(s, FUN = var)
##
simplify2array(colapply_simple_triplet_matrix(s, identity))
##
crossapply_simple_triplet_matrix(s, FUN = var)

slam

Sparse Lightweight Arrays and Matrices

v0.1-48
GPL-2
Authors
Kurt Hornik [aut, cre] (<https://orcid.org/0000-0003-4198-9911>), David Meyer [aut], Christian Buchta [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.