| melt {mefa} | R Documentation |
The function converts a wide formatted 'mefa' object into a long formatted 'stcs' object. The resulting segment column can take various formats.
melt(x, ...) ## S3 method for class 'mefa': melt(x, segm.var = NULL, by.samp = TRUE, raw.out = FALSE, drop.zero = FALSE, ...)
x |
an object of class 'mefa'. |
segm.var |
NULL (default) or column indices of samples (if by.samp = TRUE) or taxa tables (if by.samp = FALSE). If it refers to more than one column, their interaction is taken. If NULL, the resulting segment column is filled with "undefined". |
by.samp |
logical, if TRUE (default) segm.var is taken from the samples table (x$samp), if FALSE segm.var is taken from the taxa table (x$taxa). |
raw.out |
logical, whether the result should contain all the zeros that is in the crosstabulated (wide) matrix (TRUE) or not (FALSE, default). Removing the zeros is straightforward for sparse matrices. But empty samples can be ratained if drop.zero = FALSE. Works only if drop.zero = FALSE. |
drop.zero |
logical, whether samples with zero total count should be leaved out (TRUE) or not (FALSE, default). |
... |
other arguments passed to the function stcs. |
Besides the goal to convert from wide format to long format, this 'mefa' specific implementation is also useful, if a segment is not coded along with the long formatted database, but can be found in a linked table of samples or species. In this way, a 'mefa' object with new segments can be defined easily.
If melting is done with a vector that is not part of the tables inside the 'mefa' object, it must have a class attribute to be recognised, use e.g. the as.factor function (see 'Examples').
An object of class 'stsc'.
Péter Sólymos, solymos@ualberta.ca
Sólymos P. 2008. mefa: an R package for handling and reporting count data. Community Ecology 9, 125–127.
http://mefa.r-forge.r-project.org/
The generic function melt can also be found in the reshape package of Hadley Wickham, along with methods for data frames, arrays and lists (melt.default, melt.data.frame, melt.array).
Similar function in the Hmisc package by Frank Harrel is the reShape.
Similar function in the simba package by Gerald Jurasinski is the liste.
data(DOLINAcounts, DOLINAsamples, DOLINAtaxa)
x <- mefa(stcs(DOLINAcounts), DOLINAsamples, DOLINAtaxa)
## Long format with undefined segment
melt(x)
## These two are identical
melt(x, "microhab")
melt(x, x$samp$microhab) ## this is a factor
## Using a simple vector as factor
melt(x, as.factor(rbinom(dim(x)[1], 1, 0.5)))
## Interaction
melt(x, c("method", "microhab"))
## From taxa table
melt(x, "familia", by.samp = FALSE)