get.lower.tri-get.upper.tri: Vectorize the upper and lower triangular matrix In AEBilgrau/Bmisc: Biostatistical miscellaneous functions

Description

Get and set the upper and lower triangular matrix in vector form.

Usage

 ```1 2 3 4 5 6 7``` ```get.lower.tri(x, diag = FALSE) get.lower.tri(x, diag = FALSE) <- value get.upper.tri(x, diag = FALSE) get.upper.tri(x, diag = FALSE) <- value ```

Arguments

 `x` A `matrix`. `diag` logical. Should the diagonal be included? `value` A vector of the same data type a `x` of the same length as `get.lower.tri`.

Details

The returned length is dependent on `diag`. If `diag == TRUE`, then the length is `ncol(x)*(ncol(x)-1)/2`. If `FALSE`, then the length is `ncol(x)*(ncol(x)+1)/2`.

Value

`get.lower.tri` returns a numeric vector of the entries in the below the diagonal of `x`. The length is dependent on argument `diag`.

`get.upper.tri` returns a numeric vector of the entries in the below the diagonal of `x`. The length is dependent on argument `diag`.

Author(s)

Anders Ellern Bilgrau <anders.ellern.bilgrau (at) gmail.com>

`lower.tri`, `upper.tri`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15``` ```print(x <- matrix(1:25, ncol = 5)) get.lower.tri(x) get.lower.tri(x, diag = TRUE) print(y <- matrix(1:9, ncol = 3)) get.upper.tri(y) get.upper.tri(y, diag = TRUE) get.upper.tri(y) <- get.lower.tri(y) # Fill the upper tri with the lower print(y) get.upper.tri(y) print(x) get.lower.tri(x, diag = TRUE) <- get.upper.tri(x, diag = TRUE) print(x) ```