diag,rvar-method | R Documentation |
Extract the diagonal of a matrix or construct a matrix, including random
matrices (2-dimensional rvar
s). Makes base::diag()
generic.
## S4 method for signature 'rvar'
diag(x = 1, nrow, ncol, names = TRUE)
x |
(numeric,rvar) a matrix, vector, 1D array, missing, or a 1- or
2-dimensional |
nrow , ncol |
optional dimensions for the result when |
names |
(when |
Makes base::diag()
into a generic function. See that function's documentation
for usage with numeric
s and for usage of diag<-
, which is also supported
by rvar
.
For rvar
s, has two modes:
x
is a matrix-like rvar
: it returns the diagonal as a vector-like rvar
x
is a vector-like rvar
: it returns a matrix-like rvar
with x
as
the diagonal and zero for off-diagonal entries.
base::diag()
# Sigma is a 3x3 covariance matrix
Sigma <- as_draws_rvars(example_draws("multi_normal"))$Sigma
Sigma
diag(Sigma)
diag(Sigma) <- 1:3
Sigma
diag(as_rvar(1:3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.