unwrap.matrix: Convert between a matrix and a long-format data.frame

View source: R/matrix.R

unwrap.matrixR Documentation

Convert between a matrix and a long-format data.frame

Description

Convert between a matrix and a long-format data.frame

Usage

unwrap.matrix(x)

rewrap.matrix(x, na.value = NA)

Arguments

x

In case of unwrap.matrix(), a matrix to unwrap; in case of rewrap.matrix, a data.frame with three columns, respectively representing the row name, column name, and value.

na.value

Which value to use in the matrix for elements not provided in x

Value

unwrap.matrix() returns a data.frame with three columns: row and col indicating the row and column names, and value indicating the respective value in the matrix. If no row or column names are available, the row or column number is used instead.

rewrap.matrix() returns a matrix.

Author(s)

Sercan Kahveci

Examples

mymatrix <- matrix(1:40,ncol=8,nrow=5)
unwrap.matrix(mymatrix)
rewrap.matrix(unwrap.matrix(mymatrix))

carmatrix <- as.matrix(mtcars)
unwrap.matrix(carmatrix)
rewrap.matrix(unwrap.matrix(carmatrix))


Spiritspeak/skMisc documentation built on April 12, 2025, 5:40 a.m.