powered by
Methods to efficiently calculate a matrix trace depending on the class of matrix.
tr(X, ...)# S3 method for default tr(X, ...)# S3 method for dgCMatrix tr(X, ...)# S3 method for dsCMatrix tr(X, ...)
# S3 method for default tr(X, ...)
# S3 method for dgCMatrix tr(X, ...)
# S3 method for dsCMatrix tr(X, ...)
A matrix.
Additional arguments.
A numeric value for the sum of the diagonal elements.
numeric
default: Default method
default
dgCMatrix: Method for matrix X of class Matrix:::dgCMatrix
dgCMatrix
X
dsCMatrix: Method for matrix X of class Matrix:::dsCMatrix
dsCMatrix
# NOT RUN { 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 # }
Run the code above in your browser using DataLab