matrix_to_stack: Matrix to stacked (= tidy) data.frame

matrix_to_stackR Documentation

Matrix to stacked (= tidy) data.frame

Description

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.

Usage

matrix_to_stack(
  my_mat,
  value_col = "value",
  row_to_col = names(dimnames(my_mat))[1],
  col_to_col = names(dimnames(my_mat))[2]
)

Arguments

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)

Value

a stacked (= tidy) data.frame with, a column for row names, one for column names and a third one for the values.

See Also

stack_to_matrix() for the reverse operation

Examples

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)


funrar documentation built on Sept. 23, 2022, 5:10 p.m.