Learn R Programming

arkhe (version 0.3.1)

mutator: Get or Set Parts of an Object

Description

Getters and setters to retrieve or set parts of an object.

Usage

has_groups(x)

get_groups(x)

set_groups(x) <- value

get_samples(x)

set_samples(x) <- value

get_totals(x)

set_totals(x) <- value

# S4 method for AbundanceMatrix has_groups(x)

# S4 method for AbundanceMatrix get_groups(x)

# S4 method for AbundanceMatrix get_samples(x)

# S4 method for CompositionMatrix get_totals(x)

# S4 method for OccurrenceMatrix get_totals(x)

# S4 method for AbundanceMatrix set_groups(x) <- value

# S4 method for AbundanceMatrix set_samples(x) <- value

# S4 method for CompositionMatrix set_totals(x) <- value

Arguments

x

An object from which to get or set element(s) (typically a *Matrix object).

value

A possible value for the element(s) of x.

Value

An object of the same sort as x with the new values assigned.

See Also

Other mutator: subset()

Examples

Run this code
# NOT RUN {
## Create an incidence (presence/absence) matrix
## Data will be coerced with as.logical()
A <- IncidenceMatrix(data = sample(0:1, 100, TRUE, c(1, 1/3)), nrow = 20)
## Create a count data matrix
B <- CountMatrix(data = sample(0:10, 100, TRUE), nrow = 20)

## Access
dim(B) # Get the matrix dimensions
row(B) # Get the row indexes
col(B, as.factor = TRUE) # Get the column indexes
nrow(B) # Get the number of rows
ncol(B) # Get the number of columns
dimnames(B) # Get the dimension names
rownames(B) <- LETTERS[1:20] # Set the row names
rownames(B) # Get the rownames
colnames(B) <- letters[21:25] # Set the column names
colnames(B) # Get the column names

## Subset
B[[1, 1]] # Get the first value
B[1] # Get the first value
B[, ] # Get all values
B[1, , drop = FALSE] # Get the first row
B[, 1:3] # Get the first three column
# }

Run the code above in your browser using DataLab