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 you want to transform in stacked (= tidy) data.frame
(optional) character vector to use for value column (default: 'value')
(optional) character vector used for name of column in data.frame corresponding to rows in matrix (default: corresponding dimension name)
(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)
#> 'data.frame': 6150 obs. of 3 variables:
#> $ species: chr "Agro.rupe" "Agro.rupe" "Agro.rupe" "Agro.rupe" ...
#> $ site : chr "AR07" "AR71" "AR26" "AR54" ...
#> $ value : int 0 0 3 0 0 0 2 0 0 3 ...