Diag.fill: Diagonal Matrix

View source: R/Diag.R

Diagonal MatrixR Documentation

Diagonal Matrix

Description

Fill the diagonal of a matrix or create a diagonal and initialize it with a specific value.

Usage

Diag.fill(x,v=0)
Diag.matrix(len,v=0)

Arguments

x

A matrix with data.

len

Number of columns or rows.

v

Value or vector to initialize the diagonal of a matrix.By default "v=0".

Value

Diag.fill returns a diagonal matrix where all the elements in the diagonal are equal to "v".

Diag.matrix returns a diagonal matrix where has dimension "len,len" and all the elements in the diagonal are equal to "v". It is fast for huge matrices with dimensions more than [row,col] = [500,500]

Author(s)

Manos Papadakis

R implementation and documentation: Manos Papadakis <papadakm95@gmail.com>.

See Also

rowMins, colFalse, nth, rowrange, rowMedians, rowVars, colSort, rowSort, colTrue

Examples

x <- matrix(rbinom(100*100,1,0.5),100,100)

f <- Diag.fill(x,1)
f <- Diag.fill(x,1:100) ##equals to diag(x)<-1:100
f <- Diag.matrix(100,1) ##equals to diag(1,100,100)
f <- Diag.matrix(100,1:100) ##equals to diag(1:100,100,100)

f<-x<-NULL

Rfast documentation built on Nov. 9, 2023, 5:06 p.m.