tr {gremlin}R Documentation

Matrix trace methods.

Description

Methods to efficiently calculate a matrix trace depending on the class of matrix.

Usage

tr(X, ...)

## Default S3 method:
tr(X, ...)

## S3 method for class 'dgCMatrix'
tr(X, ...)

## S3 method for class 'dsCMatrix'
tr(X, ...)

Arguments

X

A matrix.

...

Additional arguments.

Value

A numeric value for the sum of the diagonal elements.

Methods (by class)

Author(s)

matthewwolak@gmail.com

Examples

  M <- matrix(seq(9), nrow = 3)
  tr(M)
  # Create sparse 'Matrix'
  dgcM <- as(M, "dgCMatrix")
  # compare `tr()` methods
  tr(M) == tr(dgcM)  #<-- should be TRUE

[Package gremlin version 0.1.0.1 Index]