upperTriangle {gdata}R Documentation

Extract or replace the upper/lower triangular portion of a matrix

Description

Extract or replace the upper/lower triangular portion of a matrix

Usage

upperTriangle(x, diag=FALSE)
upperTriangle(x, diag=FALSE) <- value
lowerTriangle(x, diag=FALSE)
lowerTriangle(x, diag=FALSE) <- value

Arguments

x Matrix
diag Logical. If code{TRUE}, include the matrix diagonal.
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 x.

Value

upperTriangle(x) and lowerTriangle(x) return the upper or lower triangle of matrix x, respectively. The assignment forms replace the upper or lower traingular area of the matrix with the provided value(s).

Author(s)

Gregory R. Warnes gregory.r.warnes@pfizer.com

See Also

diag

Examples

  x <- matrix( 1:25, nrow=5, ncol=5)
  x
  upperTriangle(x)
  upperTriangle(x, diag=TRUE)

  lowerTriangle(x)
  lowerTriangle(x, diag=TRUE)

  upperTriangle(x) <- NA
  x

  upperTriangle(x, diag=TRUE) <- 1:15
  x

  lowerTriangle(x) <- NA
  x

  lowerTriangle(x, diag=TRUE) <- 1:15
  x


[Package gdata version 2.1.2 Index]