Mefa: 'Mefa' Class

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

View source: R/Mefa.R

Description

Creating an object of class "Mefa".

Usage

1
Mefa(xtab, samp, taxa, join = c("left", "inner"), drop = FALSE)

Arguments

xtab

a matrix or a sparse matrix.

samp

a data frame or NULL.

taxa

a data frame or NULL.

join

character, "left" (default) or "inner".

drop

logical, if unused levels in the data frames should be dropped.

Details

samp and taxa tables are matched with corresponding dimnames in xtab: rownames with samp, colnames with taxa. If join = "left", all rows and columns in xtab are retained, while missing items in the corresponding attribute tables are filled up with NAs. If join = "inner", only the intersection of corresponding names are retained.

The xtab slot is a sparse matrix (dgCMatrix). The input should be in class MefaMatrix that is a class union of matrix and sparseMatrix classes.

The samp and taxa slots take data frame or NULL, which two form the MefaDataFrame class union.

The virtual classes mefa and stcs are defined for seamless coercion between S3 and S4 classes.

Value

An S4 object of class "Mefa" with 4 slots: xtab, samp, taxa, join.

Note

If xtab has no dimnames, matching it up with the attribute tables can be problematic.

Author(s)

Peter Solymos <solymos@ualberta.ca>

See Also

Creating crosstabulations: Xtab, xtabs in package stats, xtabs in package stats

"mefa" S3 class: mefa in mefa package.

Accessing and replacing slots: xtab, samp, taxa.

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
x <- 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),
    stringsAsFactors = TRUE)
samp <- data.frame(samples=levels(x$sample), var1=1:2,
    stringsAsFactors = TRUE)
taxa <- data.frame(specnames=levels(x$species), var2=c("b","a"),
    stringsAsFactors = TRUE)
rownames(samp) <- samp$samples
rownames(taxa) <- taxa$specnames

## Xtab class, counts by repetitions in RHS
(x0 <- Xtab(~ sample + species, x))

## counts by LHS and repetitions in RHS
(x1 <- Xtab(count ~ sample + species, x))

## drop all empty rows
(x2 <- Xtab(count ~ sample + species, x, cdrop=FALSE,rdrop=TRUE))

## drop all empty columns
Xtab(count ~ sample + species, x, cdrop=TRUE,rdrop=FALSE)

## drop specific columns by placeholder
Xtab(count ~ sample + species, x, cdrop="zero.pseudo")

## Mefa class, standard
(x3 <- Mefa(x1, samp, taxa))
unclass(x3)
x3@xtab
x3@samp
x3@taxa
x3@join

## effects of left join, NULL taxa slot, xtab is (not sparse) matrix
(x4 <- Mefa(as.matrix(x1), samp[1:2,]))
unclass(x4)

## effects of inner join (intersect)
(x5 <- Mefa(x2, samp, taxa, join="inner"))
unclass(x5)
unclass(Mefa(x1, samp[1:2,], join="inner"))

## xtab only Mefa
(x6 <- Mefa(x1))

## creating new Mefa object without Mefa()
new("Mefa", xtab=x1, samp=samp, taxa=taxa,join="left")

## dim and dimnames
dim(x5)
dimnames(x5)
dn <- list(paste("S", 1:3, sep=""), paste("SPP", 1:4, sep=""))
dimnames(x5) <- dn
unclass(x5)
dimnames(x5)[[1]] <- paste("S", 1:3, sep="_")
unclass(x5)
dimnames(x5)[[2]] <- paste("SPP", 1:4, sep="_")
unclass(x5)

## transpose
x5
t(x5)
unclass(x5)
unclass(t(x5))

## 0 and 1 row/col Mefa object
x3[c(FALSE,FALSE,FALSE,FALSE),c(FALSE,FALSE,FALSE,FALSE)]
x3[c(TRUE,FALSE,FALSE,FALSE),c(FALSE,FALSE,FALSE,FALSE)]
x3[c(FALSE,FALSE,FALSE,FALSE),c(TRUE,FALSE,FALSE,FALSE)]
x3[c(TRUE,FALSE,FALSE,FALSE),c(TRUE,FALSE,FALSE,FALSE)]

## stack
stack(x3)

mefa4 documentation built on Oct. 7, 2021, 1:06 a.m.