R/tr.R
tr.Rd
Calculates the trace of a square numeric matrix, i.e., the sum of its diagonal elements
tr(X)
a numeric matrix
a numeric value, the sum of diag(X)
diag(X)
X <- matrix(1:9, 3, 3) tr(X) #> [1] 15