coerce: Coerce Methods for 'Vegsoup*' objects

Description Usage Arguments Details Value Warning Author(s) See Also Examples

Description

Coerce object a 'Vegsoup*' object to other class.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## S4 method for signature 'Vegsoup,matrix'
coerce(from,to,strict = TRUE)
## S4 method for signature 'Vegsoup,array'
coerce(from,to,strict = TRUE)
## S4 method for signature 'Vegsoup,dist'
coerce(from,to,strict = TRUE)
## S4 method for signature 'Vegsoup,sparseMatrix'
coerce(from,to,strict = TRUE)
## S4 method for signature 'Vegsoup,dsparseMatrix'
coerce(from,to,strict = TRUE)
## S4 method for signature 'Vegsoup,list'
coerce(from,to,strict = TRUE)
## S4 method for signature 'Vegsoup,data.frame'
coerce(from,to,strict = TRUE)
#\S4method{coerce}{Vegsoup,data.list}(from,to,strict = TRUE)
## S4 method for signature 'Vegsoup,mefa'
coerce(from,to,strict = TRUE)
## S4 method for signature 'Vegsoup,SpatialPoints'
coerce(from,to,strict = TRUE)
## S4 method for signature 'Vegsoup,SpatialPointsDataFrame'
coerce(from,to,strict = TRUE)
## S4 method for signature 'coenocline,Vegsoup'
coerce(from,to,strict = TRUE)

Arguments

from

A Vegsoup* object.

to

class to coerce to.

strict

If TRUE, the returned object must be strictly from the target class.

Details

These are generic coerce methods to ensure that S3 functions dispatch properly, especially regarding the as(x, "matrix") and as(x, "dist") coercion methods. In this way it is almost always possible to supply a 'Vegsoup*' object directly to functions for multivariate analysis (see ‘Examples’). Note, the matrix coercion retrieves a species matrix according to the defaults of as.matrix and the list coercion calls as.matrix(x, typeof = "character", mode = "Q").

Coercion to sparse matrices is currently rather limited.

Value

Coercion to 'matrix' and 'sparseMatrix' returns an object of the corresponding class. Coercion to 'list' returns a list with three components.

species

object of class 'matrix'

sites

object of class 'data.frame'

taxonomy

object of class 'data.frame'

Coercion to 'data.frame' returns a "data.frame" with as many row as there are in species(x).

Coercion to 'array' returns an "array".

Coercion to 'mefa' and 'data.list' returns a "mefa" respectively "data.list" object.

Warning

S3 functions must contain a call to as.matrix to guarantee dispatch. For example metaMDS(obj) does not work, but other functions in package vegan will. Note, if a function that expects a species matrix calls as.data.frame in the function body it will certainly break, because the as.data.frame(x) coercion does not return a species matrix (see as.data.frame)!

Coercion to class "mefa" is only meaningful for count data!

Author(s)

Roland Kaiser

See Also

as.matrix, as.dist

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require(vegsoup)
require(cluster)

data(barmstein)
x <- barmstein

# same as as.matrix(prt, typeof = "numeric")
m <- as(x, "matrix")

# the species matrix as an multi-dimensional array
a <- as(x, "array")

# the data stored in slots 'species', 'sites' and 'taxonomy'
l <- as(x, "list")
length(l)

# coerce to data.list in package multitable
# package multitable was removed from the CRAN (2016-05-02)
# xdl <- as(x, "data.list")
# summary(xdl)

# automatic dispatch of Vegsoup* object as argument in S3 function
# if they internally call as.matrix or as.dist
decostand(x) <- "hellinger"
vegdist(x) <- "euclidean"

rda(x) # principal component analysis

agnes(x) # agglomerative nesting

# no call to as.dist(d) in hclust, no automatic dispatch
hclust(as.dist(x))

vegsoup documentation built on Feb. 24, 2021, 3 a.m.