Learn R Programming

arkhe (version 0.2.2)

mutator: Get or Set Parts of an Object

Description

Getters and setters to extract or replace parts of an object.

Usage

get_id(object)

get_method(object)

get_units(object)

get_totals(object)

set_totals(object) <- value

# S4 method for ANY get_id(object)

# S4 method for AbundanceMatrix get_totals(object)

# S4 method for SimilarityMatrix get_method(object)

# S4 method for StratigraphicMatrix get_units(object)

# S4 method for AbundanceMatrix set_totals(object) <- value

Arguments

object

An object from which to get or set element(s).

value

A possible value for the element(s) of object (see below).

Value

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

See Also

Other mutator: subset()

Examples

Run this code
# NOT RUN {
## Create a count data matrix
A1 <- CountMatrix(data = sample(0:10, 100, TRUE), nrow = 10, ncol = 10)

## Access
get_id(A1)
dim(A1) # Get the matrix dimensions
colnames(A1) <- letters[11:20] # Set the column names
colnames(A1) # Get the column names
rownames(A1) <- LETTERS[1:10] # Set the row names
rownames(A1) # Get the rownames

## Subset
A1[[1]] # Get the first value
A1[, ] # Get all values
A1[1, ] # Get the first row
A1[c("A", "B", "C"), ] # Get the first three rows
A1[c("A", "B", "C"), 1] # Get the first three rows of the first column
A1[, 1, drop = FALSE] # Get the first column

## Coerce counts to relative frequencies
B <- as_abundance(A1)
## Row sums are internally stored before coercing to a frequency matrix
get_totals(B) # Get row sums
## This allows to restore the source data
A2 <- as_count(B)
all(A1 == A2)
## Coerce to a co-occurrence matrix
B <- as_occurrence(A1)
# }

Run the code above in your browser using DataLab