Operators acting on objects to extract or replace parts.

# S4 method for Matrix
[(x, i, j) <- value

# S4 method for Matrix
[[(x, i, j) <- value

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.

value

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

Value

A subsetted object.

See also

Other mutator: mutator

Examples

## Create a count data matrix A1 <- CountMatrix(data = sample(0:10, 100, TRUE), nrow = 10, ncol = 10) ## Access get_id(A1)
#> [1] "b58a0e95-cf3e-4feb-a8fe-d0f8590b2a4d"
dim(A1) # Get the matrix dimensions
#> [1] 10 10
colnames(A1) <- letters[11:20] # Set the column names colnames(A1) # Get the column names
#> [1] "k" "l" "m" "n" "o" "p" "q" "r" "s" "t"
rownames(A1) <- LETTERS[1:10] # Set the row names rownames(A1) # Get the rownames
#> [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
## Subset A1[[1]] # Get the first value
#> [1] 2
A1[, ] # Get all values
#> k l m n o p q r s t #> A 2 8 7 9 4 9 8 3 7 6 #> B 0 6 6 9 10 0 2 0 7 8 #> C 9 0 4 10 1 6 7 9 8 9 #> D 8 6 4 5 2 1 3 4 5 10 #> E 0 4 8 10 1 6 9 0 10 10 #> F 7 9 0 4 9 3 8 0 0 9 #> G 3 3 5 3 4 6 7 9 8 2 #> H 1 10 2 5 6 2 0 6 6 4 #> I 9 8 4 4 0 2 2 5 2 6 #> J 1 9 3 0 5 10 6 8 7 9
A1[1, ] # Get the first row
#> k l m n o p q r s t #> 2 8 7 9 4 9 8 3 7 6
A1[c("A", "B", "C"), ] # Get the first three rows
#> k l m n o p q r s t #> A 2 8 7 9 4 9 8 3 7 6 #> B 0 6 6 9 10 0 2 0 7 8 #> C 9 0 4 10 1 6 7 9 8 9
A1[c("A", "B", "C"), 1] # Get the first three rows of the first column
#> A B C #> 2 0 9
A1[, 1, drop = FALSE] # Get the first column
#> k #> A 2 #> B 0 #> C 9 #> D 8 #> E 0 #> F 7 #> G 3 #> H 1 #> I 9 #> J 1
## 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
#> A B C D E F G H I J #> 63 48 63 48 58 49 50 42 42 58
## This allows to restore the source data A2 <- as_count(B) all(A1 == A2)
#> [1] TRUE
## Coerce to a co-occurrence matrix B <- as_occurrence(A1)