Sq2Long: 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
Sq2Long(x, col.names = NULL, keep = c(T, T, T), drop.values = 0,
  drop.NA = T)

Arguments

x

A square matrix to reshape into a dataframe.

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)
Sq2Long(demo_mat, c('A', 'B', 'value'))
Sq2Long(demo_mat, c('A', 'B', 'value'), drop.values = 0, drop.NA = FALSE)

Rnets documentation built on July 23, 2019, 9:04 a.m.