tr: Find the trace of a square matrix

Description Usage Arguments Details Value Examples

Description

Hardly worth coding, if it didn't appear in so many formulae in psychometrics, the trace of a (square) matrix is just the sum of the diagonal elements.

Usage

1
tr(m)

Arguments

m

A square matrix

Details

The tr function is used in various matrix operations and is the sum of the diagonal elements of a matrix.

Value

The sum of the diagonal elements of a square matrix.
i.e. tr(m) <- sum(diag(m)).

Examples

1
2
3
4
 m <- matrix(1:16,ncol=4)
 m
 tr(m)
 

frenchja/psych documentation built on May 16, 2019, 2:49 p.m.