extract_tri: extract upper or lower triangle from a square matrix

extract_triR Documentation

extract upper or lower triangle from a square matrix

Description

extract upper or lower triangle from a square matrix

Usage

extract_tri(square.matrix, result.file, upper = FALSE, keep.diag = TRUE)

Arguments

square.matrix

a pairwise matrix object

result.file

a character string name of your result file

upper

a logical indicating that you want to keep the upper triangle (default=FALSE)

keep.diag

a logical indicating that you want to keep the diagonal in your trimat (default=TRUE)

Value

a trimatrix object and .csv file

Author(s)

Chris Brauer

Examples

 ## set directory for results to be written
 setwd("path/to/working/directory")

 # load example matrix
 example.mat <- matrix(c(0,3,5,6, 3,0,6,6, 5,6,0,3, 6,6,3,0), 
                nrow = 4, ncol = 4, dimnames = list(c("A", "B", "C", "D"), 
                c("A", "B", "C", "D")))

 # extract lower trimarix
 Lmat <- extract_tri(example.mat, "lowermat")
 
 # extract upper trimarix without the diagonal
 Umat <- extract_tri(example.mat, "uppermat", upper = TRUE, keep.diag = FALSE)

pygmyperch/melfuR documentation built on April 19, 2024, 7:24 a.m.