matrix_to_stack | R Documentation |
From a matrix with values to a stacked (= tidy) data.frame, exclude NA from
given data.frame. If supplied object is not a matrix, try to coerce object
to matrix first. matrix_to_tidy()
is an alias of this function.
matrix_to_stack( my_mat, value_col = "value", row_to_col = names(dimnames(my_mat))[1], col_to_col = names(dimnames(my_mat))[2] )
my_mat |
matrix you want to transform in stacked (= tidy) data.frame |
value_col |
(optional) character vector to use for value column (default: 'value') |
row_to_col |
(optional) character vector used for name of column in data.frame corresponding to rows in matrix (default: corresponding dimension name) |
col_to_col |
(optional) character vector used for name of column in data.frame corresponding to columns in matrix (default: corresponding dimension name) |
a stacked (= tidy) data.frame with, a column for row names, one for column names and a third one for the values.
stack_to_matrix()
for the reverse operation
data("aravo", package = "ade4") # Site-species matrix converted into data.frame mat = as.matrix(aravo$spe) dat = matrix_to_stack(mat, "value", "site", "species") str(dat)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.