gather_matrix | R Documentation |
Converts a matrix into a data frame with one row for each matrix entry and
three columns. This is the same idea as the gather
function from the tidyr package, but for the matrix special case. The
result is in row-major order by default. An ordinary matrix m is
unrolled into triplets i, j, m_{ij}. If row or column names are present
they are swapped in for the numeric indices, or you can supply these
directly.
gather_matrix( m, row_values = rownames(m), col_values = colnames(m), col_names = c("row_key", "col_key", "value"), row_major = TRUE )
m |
matrix (or Matrix: but sparse matrices will be filled in) |
row_values |
values corresponding to row indices. By default the row
names of |
col_values |
similarly, for columns. |
col_names |
names for the columns of the resulting data frame |
row_major |
unroll |
a data frame with three columns and one row for every entry of
m
.
m <- matrix(1:4, ncol=2, byrow=TRUE) gather_matrix(m)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.