stack_to_matrix | R Documentation |
Passes from a stacked (= tidy) data.frame to a matrix. tidy_to_matrix()
is
an alias of this function.
stack_to_matrix( my_df, col_to_row, col_to_col, col_value = NULL, sparse = FALSE )
my_df |
data.frame you want to transform in matrix |
col_to_row |
character vector of the name of the data.frame column you want to put into matrix rows |
col_to_col |
character vector of the name of the data.frame column you want to be as columns in matrix |
col_value |
(optional, default = |
sparse |
(optional, default = |
a matrix with given col_to_row
column in rows and col_to_col
column in columns. If some cells are not present in the data.frame (e.g. some
species not present at some sites), the matrix will have a NA
value.
matrix_to_stack()
for the reverse operation
example = data.frame("sites" = c(rep("1", 3), rep("2", 2)), "species" = c("A", "B", "C", "B", "D"), "abundance" = c(0.33, 0.33, 0.33, 0.4, 0.6)) mat = stack_to_matrix(example, "sites", "species", "abundance") mat
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.