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
)
data.frame you want to transform in matrix
character vector of the name of the data.frame column you want to put into matrix rows
character vector of the name of the data.frame column you want to be as columns in matrix
(optional, default = NULL
) character vector indicating
the name of a column coding the values that will be put in
the matrix
(optional, default = FALSE
) logical indicating whether to
return a sparse matrix (if TRUE
requires
tidytext
package)
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