samp: Accessing and Replacing Parts of 'Mefa' Objects

sampR Documentation

Accessing and Replacing Parts of 'Mefa' Objects

Description

Methods to access and replace parts (elements, slots) of "Mefa" objects.

Usage

xtab(x)
"xtab<-"(x, value)

samp(x)
"samp<-"(x, value)

taxa(x)
"taxa<-"(x, value)

Arguments

x

an object of S4 class "Mefa".

value

replacement value.

Details

The [ method ensures that the xtab sparse matrix part and the corresponding attribute tables are subsetted correctly.

Validity check is performed when replacing slots of an object.

Value

An object of S4 class "Mefa".

Author(s)

Peter Solymos <solymos@ualberta.ca>

See Also

Mefa

Examples

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
x1 <- Xtab(count ~ sample + species, x)
x3 <- Mefa(x1, samp, taxa)

## accessing the xtab slot
xtab(x3)
## replacing the slot value
x1[3,1] <- 999
xtab(x3) <- x1
xtab(x3)

## accessing and replacing the samp slot
samp(x3)
samp(x3) <- NULL
samp(x3)
samp(x3) <- samp[1:3,]
samp(x3)

## accessing and replacing the taxa slot
taxa(x3)
taxa(x3) <- NULL
taxa(x3)
taxa(x3) <- taxa[1:3,]
taxa(x3)

## subsetting
unclass(x3[3:2, 1:2])
unclass(x3[3:2,])
unclass(x3[,1:2])

mefa4 documentation built on Sept. 12, 2022, 5:05 p.m.