Learn R Programming

mefa4 (version 0.3-11)

Melt: Melting Matrices

Description

The function reverses the side effects of cross tabulation.

Usage

Melt(x)

Value

A data frame with columns corresponding to rows, cols, possibly segm (names of the list if x was a list of sparse matrices), and value. value is numeric, other columns are factors.

Arguments

x

A matrix, or sparse matrix object, a list of sparse matrices with identical dimnames, a 'mefa' or 'Mefa' object.

Author

Peter Solymos <solymos@ualberta.ca>

See Also

stack in utils, and melt in mefa package.

Examples

Run this code
xx <- data.frame(
    sample = paste("Sample", c(1,1,2,2,3,4), sep="."),
    species = c(paste("Species", c(1,1,1,2,3), sep="."),  "zero.pseudo"),
    count = c(1,2,10,3,4,0),
    segment = letters[c(6,13,6,13,6,6)],
    stringsAsFactors = TRUE)
xx
xx0 <- Xtab(count ~ sample + species, xx)
xx1 <- Xtab(count ~ sample + species + segment, xx)
(M1 <- Melt(xx0))
Melt(as.matrix(xx0))
(M2 <- Melt(xx1))
stopifnot(identical(Xtab(value ~ rows + cols, M1), xx0))
stopifnot(identical(Xtab(value ~ rows + cols + segm, M2), xx1))

Run the code above in your browser using DataLab