Learn R Programming

mefa (version 3.2-9)

as.mefa: Conversion Among Various Object Classes

Description

These functions coerce into class 'mefa' or 'stcs'; or converts 'mefa' or 'stcs' obects into a 'data.frame', 'matrix', 'array', 'list'.

Usage

as.stcs(x, ...)
# S3 method for default
as.stcs(x, ...)
as.mefa(x, ...)
as.Mefa(x, ...)
as.Xtab(x, ...)
# S3 method for default
as.mefa(x, samp, taxa, ...)
# S3 method for array
as.mefa(x, ...)
# S3 method for list
as.mefa(x, ...)
# S3 method for mefa
as.matrix(x, ...)
# S3 method for mefa
as.array(x, ...)
# S3 method for mefa
as.list(x, ...)
# S3 method for stcs
as.data.frame(x, ...)
# S3 method for mefa
as.data.frame(x, ..., fun, name, make.unique = FALSE)
mss(x, name, make.unique = FALSE, ...)
msr(x, name, make.unique = FALSE, ...)
mts(x, name, make.unique = FALSE, ...)
mtr(x, name, make.unique = FALSE, ...)

Value

An object of class 'stcs', 'mefa', 'matrix', 'array', 'list' or 'data.frame', depending on the method used.

Arguments

x

an object of class 'mefa'.

samp

a data frame containing rows for samples, or NULL. See argument xtab.fixed and details for sample matching options.

taxa

a data frame containing rows for taxa, or NULL. See argument xtab.fixed and details for taxa matching options.

fun

a function to determine what to return, see details. It has no default, because the choice is not trivial.

name

optional character vector, names to return if not all possible elements are needed, see details.

make.unique

logical, useful to use make.unique = TRUE if names to return are non-unique, see details.

...

other arguments passed to the generic function as.data.frame.

Author

P\'eter S\'olymos, solymos@ualberta.ca

Details

The usage of most of these coercion methods is trivial. Arrays and lists can be coerced into 'mefa' objects as if those were the segm element of it (either nested, or non nested). The reverse is true, when coercing an object of class 'mefa' into list or array, the segm element is used.

Coercing among object classes 'matrix' and 'mefa' is done via using the xtab element.

By as.data.frame.mefa, four kinds of data frames can be returned, depending on the function used as the fun argument: mss returns summary statistics for samples (richness and abundance) and x$samp; msr returns raw data (x$xtab) and x$samp; mts returns summary statistics for taxa (occurrence and abundance) and x$taxa; mtr returns raw data (t(x$xtab)) and x$taxa.

The name can be used if only a subset of the summary statistics, or raw data should be returned. The character vector should contain names of elements to return (see examples).

It might (rarely) occur, that names of the summary statistics, or the raw data and the column names of the sample/taxa table overlap (contains names that are common in the two set). In this case, the make.unique = TRUE can be used to resolve non-uniqueness and avoid the error message produced otherwise.

The functions supplied as the fun argument can be used separately. Although the usage of the as.data.frame method is more transparent.

References

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. tools:::Rd_expr_doi("10.18637/jss.v029.i08")

http://mefa.r-forge.r-project.org/

See Also

Examples

Run this code
data(dol.count, dol.samp, dol.taxa)
x <- mefa(stcs(dol.count), dol.samp, dol.taxa)
## These two are equivalent
as.data.frame(x, fun = mss)
mss(x)
## Return only two species
as.data.frame(x, fun = msr, c("iiso", "ppyg"))
## Taxa table and summary
as.data.frame(x, fun = mts)
## Taxa table and raw data transpose
as.data.frame(x, fun = mtr)
## Why is it useful?
## Instead of
glm(x$xtab[,"amin"] ~ microhab + method, data = x$samp, family = poisson)
## it is more convenient to use
glm(amin ~ microhab + method, data = msr(x), family = poisson)

Run the code above in your browser using DataLab