A faster version of base::diag() (on larger matrices).

Diag(inMatrix)

Arguments

inMatrix

The input matrix

Value

A vector

References

http://stackoverflow.com/a/20489737/1270695

Author

Ananda Mahto

Examples

set.seed(1) m <- matrix(rnorm(100), ncol = 10) Diag(m)
#> [1] -0.626453811 0.389843236 0.074564983 -0.053805041 -0.688755695 #> [6] 1.980399899 -1.804958629 0.001105352 0.370018810 -0.473400636
diag(m)
#> [1] -0.626453811 0.389843236 0.074564983 -0.053805041 -0.688755695 #> [6] 1.980399899 -1.804958629 0.001105352 0.370018810 -0.473400636