Description Usage Arguments Details Value Author(s) References See Also Examples
The function converts a wide formatted 'mefa' object into a long formatted 'stcs' object. The resulting segment column can take various formats.
1 2 3 4 |
x |
an object of class 'mefa'. |
segm.var |
|
by.samp |
logical, if |
raw.out |
logical, whether the result should contain all the zeros that is in the crosstabulated (wide) matrix ( |
drop.zero |
logical, whether samples with zero total count should be leaved out ( |
... |
other arguments passed to the function |
If a 'mefa' objet has original segments and segm.var = NULL, the function returns original segments. In this case, the raw.out = TRUE cannot be applied (because segments have different zero samples, so the option is meaningless). If the 'mefa' object contains only a data matrix without dimnames, rows and columns are numbered before melting.
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' if raw = FALSE, pure 'data.frame' otherwise (because the zero count flag cannot be applied).
P\'eter S\'olymos, solymos@ualberta.ca
S\'olymos P. (2008) mefa: an R package for handling and reporting count data. Community Ecology 9, 125–127.
S\'olymos P. (2009) Processing ecological data in R with the mefa package. Journal of Statistical Software 29(8), 1–28. http://www.jstatsoft.org/v29/i08/
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | data(dol.count, dol.samp, dol.taxa)
x <- mefa(stcs(dol.count), dol.samp, dol.taxa)
## Long format with original segments
melt(x)
## Long format with undefined segment
melt(as.mefa(x, segment = FALSE))
## 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)
## Example for non-integer data
y <- x$xtab
y[y > 0] <- y[y > 0] + 0.123
z <- mefa(y)
melt(z)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.