View source: R/upperTriangle.R
upperTriangle | R Documentation |
Extract or replace the upper/lower triangular portion of a matrix.
upperTriangle(x, diag=FALSE, byrow=FALSE)
upperTriangle(x, diag=FALSE, byrow=FALSE) <- value
lowerTriangle(x, diag=FALSE, byrow=FALSE)
lowerTriangle(x, diag=FALSE, byrow=FALSE) <- value
x |
Matrix |
diag |
Logical. If |
byrow |
Logical. If |
value |
Either a single value or a vector of length equal to that
of the current upper/lower triangular. Should be of a mode which
can be coerced to that of |
upperTriangle(x)
and lowerTriangle(x)
return the upper
or lower triangle of matrix x, respectively. The assignment forms
replace the upper or lower triangular area of the
matrix with the provided value(s).
By default, the elements are returned/replaced in R's default column-wise order. Thus
lowerTriangle(x) <- upperTriangle(x)
will not yield a symmetric matrix. Instead use:
lowerTriangle(x) <- upperTriangle(x, byrow=TRUE)
or equivalently:
lowerTriangle(x, byrow=TRUE) <- upperTriangle(x)
Gregory R. Warnes greg@warnes.net
diag
,
lower.tri
,
upper.tri
x <- matrix(1:25, nrow=5, ncol=5)
x
upperTriangle(x)
upperTriangle(x, diag=TRUE)
upperTriangle(x, diag=TRUE, byrow=TRUE)
lowerTriangle(x)
lowerTriangle(x, diag=TRUE)
lowerTriangle(x, diag=TRUE, byrow=TRUE)
upperTriangle(x) <- NA
x
upperTriangle(x, diag=TRUE) <- 1:15
x
lowerTriangle(x) <- NA
x
lowerTriangle(x, diag=TRUE) <- 1:15
x
## Copy lower triangle into upper triangle to make
## the matrix (diagonally) symmetric
x <- matrix(LETTERS[1:25], nrow=5, ncol=5, byrow=TRUE)
x
lowerTriangle(x) = upperTriangle(x, byrow=TRUE)
x
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.