diagonal: Extract diagonal terms from a variety of matrix types

View source: R/scoremats.r

diagonalR Documentation

Extract diagonal terms from a variety of matrix types

Description

Extract diagonal terms from a variety of matrix types

Usage

diagonal(x, indices = NULL)

## Default S3 method:
diagonal(x, indices = NULL)

Arguments

x

A square matrix

indices

specifies a subset of the diagonal using a character vector of names, a logical vector or integer indices. The default (NULL) implies all elements.

Details

Insists that input matrix is square. Uses the 'diagonal' attribute when available and has specialised handling of ff, big.matrix, dgCMatrix matrices. Does not check that row and column names are identical for those matrix classes (unlike the base diag function, but always uses rownames.

Value

a named vector containing the diagonal elements.

Examples

m=fill_in_sparse_score_mat(letters[1:5])
diagonal(m)

nat.nblast documentation built on July 9, 2023, 6:12 p.m.