Mefa | R Documentation |
Creating an object of class "Mefa"
.
Mefa(xtab, samp, taxa, join = c("left", "inner"), drop = FALSE)
xtab |
a matrix or a sparse matrix. |
samp |
a data frame or |
taxa |
a data frame or |
join |
character, |
drop |
logical, if unused levels in the data frames should be dropped. |
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 NA
s.
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.
An S4 object of class "Mefa"
with 4 slots: xtab
,
samp
, taxa
, join
.
If xtab
has no dimnames, matching it up with the attribute tables can be problematic.
Peter Solymos <solymos@ualberta.ca>
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
.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.