powered by
This function resphapes all or parts of a square matrix into a 3 column table.
Sq2Long(x, col.names = NULL, keep = c(T, T, T), drop.values = 0, drop.NA = T)
A square matrix to reshape into a dataframe.
A vector indicating how output columns are named.
A logical vector of length 3 indicating which of the three respective elements to keep: upper triangle, main diagonal, and lower triangle.
A vector of values to remove from the output.
Logical value indicating if NAs should be removed.
a data.frame with three columns. Columns 1 & 2 contain the row & column names, and third contains corresponding matrix values.
# NOT RUN { 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) # }
Run the code above in your browser using DataLab