Sq2L: Matrix reshaping function

Description Usage Arguments Value Examples

View source: R/Sq2L.R

Description

This function resphapes all or parts of a square matrix into a 3 column table.

Usage

1
2
Sq2L(x, output.col.names = NULL, keep = c(T, T, T), drop.values = 0,
  drop.NA = T)

Arguments

x

A square matrix to reshape into a dataframe.

output.col.names

A vector indicating how output columns are named.

keep

A logical vector of length 3 indicating which of the three respective elements to keep: upper triangle, main diagonal, and lower triangle.

drop.values

A vector of values to remove from the output.

drop.NA

Logical value indicating if NAs should be removed.

Value

a data.frame with three columns. Columns 1 & 2 contain the row & column names, and third contains corresponding matrix values.

Examples

1
2
3
demo_mat <- matrix(c(1, 5, 2, 5, 1, 0, 2, 0, NA), nrow = 3)
Sq2L(demo_mat, c('A', 'B', 'value'))
Sq2L(demo_mat, c('A', 'B', 'value'), drop.values = 0, drop.NA = FALSE)

EpidemiologyDVM/Rnets documentation built on Dec. 8, 2017, 12:27 a.m.