A simple function returning upper or lower matrix triangle. Remaining triangle is replaced with NAs.

get_triangle(cormat, part = "upper")

Arguments

cormat

Usually correlation matrix

part

Single string vector decide whether to return upper or lower part.

Value

Object of dimensions dim(cormat) with NA values being present in lower or upper triangle.

Details

The functions as a wrapper on lower.tri and upper.tri functions.

Examples

M <- matrix(1:20, 5, 5) get_triangle(cormat = M, part = "upper")
#> [,1] [,2] [,3] [,4] [,5] #> [1,] 1 6 11 16 1 #> [2,] NA 7 12 17 2 #> [3,] NA NA 13 18 3 #> [4,] NA NA NA 19 4 #> [5,] NA NA NA NA 5