melt_matrix: Reshape a contingency table like matrix to a long data.table

View source: R/melt_matrix.R

melt_matrixR Documentation

Reshape a contingency table like matrix to a long data.table

Description

melt_matrix() takes a matrix as input, which has the shape of a contingency table. Hence, the row and column names/indices are considered as unique values of a (categorical) variable and the cells represent values associated with the respective row-column combinations. The function then transforms the data to a long data.table representation.

Usage

melt_matrix(x, name_row = "row", name_col = "column", name_val = "value")

Arguments

x

(matrix())
A matrix.

name_row

(character(1))
A string specifying the column name associated with the rows of the matrix.

name_col

(character(1))
A string specifying the column name associated with the columns of the matrix.

name_val

(character(1))
A string specifying the column name associated with the cells/values of the matrix.

Value

(data.table::data.table())
A data.table representing x in a long format.

Note

If the supplied matrix does not have row and/or column names, it will be supplied with the matching indices.
The columns of the data.table created from the row and column names are always of type "character". If a type conversion is desired, this has to be done by the user afterwards manually.


DavidJesse21/data.table.utils documentation built on March 26, 2023, 7:19 a.m.