Unlimited learning, half price | 50% off

Last chance! 50% off unlimited learning

Sale ends in


tabula (version 1.3.0)

subset: Extract or Replace Parts of an Object

Description

Operators acting on objects to extract or replace parts.

Usage

# S4 method for BootCA
[(x, i, j, drop = TRUE)

# S4 method for DateModel [(x, i, j, drop = TRUE)

# S4 method for DateModel [[(x, i)

# S4 method for BootCA [[(x, i)

# S4 method for PermutationOrder [[(x, i)

# S4 method for SpaceTime [[(x, i)

# S4 method for CountMatrix [[(x, i)

# S4 method for FrequencyMatrix [[(x, i)

# S4 method for IncidenceMatrix [[(x, i)

# S4 method for OccurrenceMatrix [[(x, i)

# S4 method for SimilarityMatrix [[(x, i)

Arguments

x

An object from which to extract element(s) or in which to replace element(s).

i, j

Indices specifying elements to extract or replace. Indices are numeric, integer or character vectors or empty (missing) or NULL. Numeric values are coerced to integer as by as.integer (and hence truncated towards zero). Character vectors will be matched to the name of the elements. An empty index (a comma separated blank) indicates that all entries in that dimension are selected.

drop

A logical scalar: should the result be coerced to the lowest possible dimension? This only works for extracting elements, not for the replacement.

Value

A subsetted object.

Examples

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

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

## Subset
A1[["id"]] # Get the matrix ID
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 frequencies
B <- as_frequency(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)
# }

Run the code above in your browser using DataLab