Learn R Programming

matlib (version 1.0.0)

tr: Trace of a Matrix

Description

Calculates the trace of a square numeric matrix, i.e., the sum of its diagonal elements

Usage

tr(X)

Value

a numeric value, the sum of diag(X)

Arguments

X

a numeric matrix

Examples

Run this code
X <- matrix(1:9, 3, 3)
tr(X)

Run the code above in your browser using DataLab