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

get_id(object)

get_totals(object)

set_totals(object) <- value

# S4 method for ANY
get_id(object)

# S4 method for FrequencyMatrix
get_totals(object)

# S4 method for FrequencyMatrix
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

## Create a count data matrix A1 <- CountMatrix(data = sample(0:10, 100, TRUE), nrow = 10, ncol = 10, byrow = TRUE) ## Access get_id(A1)
#> [1] "87cfdddf-e15e-41ec-bd6d-432ab798a5ab"
dim(A1) # Get the matrix dimensions
#> [1] 10 10
colnames(A1) # Get the column names
#> [1] "V1" "V2" "V3" "V4" "V5" "V6" "V7" "V8" "V9" "V10"
colnames(A1) <- letters[11:20] # Set the column names rownames(A1) # Get the rownames
#> [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10"
rownames(A1) <- LETTERS[1:10] # Set the row names ## Subset A1[["id"]] # Get the matrix ID
#> [1] "87cfdddf-e15e-41ec-bd6d-432ab798a5ab"
A1[, ] # Get all values
#> k l m n o p q r s t #> A 3 5 3 7 5 5 10 10 8 6 #> B 6 1 3 3 6 8 3 4 6 9 #> C 1 10 4 1 7 4 10 3 2 3 #> D 0 6 0 4 5 9 6 2 7 6 #> E 1 0 0 8 9 10 2 10 9 3 #> F 7 7 4 6 10 0 1 8 7 2 #> G 1 10 3 4 2 0 0 2 8 3 #> H 2 0 0 7 3 5 9 1 0 6 #> I 3 6 2 0 6 2 6 6 6 2 #> J 1 5 0 3 6 3 10 6 0 10
A1[1, ] # Get the first row
#> k l m n o p q r s t #> 3 5 3 7 5 5 10 10 8 6
A1[c("A", "B", "C"), ] # Get the first three rows
#> k l m n o p q r s t #> A 3 5 3 7 5 5 10 10 8 6 #> B 6 1 3 3 6 8 3 4 6 9 #> C 1 10 4 1 7 4 10 3 2 3
A1[c("A", "B", "C"), 1] # Get the first three rows of the first column
#> A B C #> 3 6 1
A1[, 1, drop = FALSE] # Get the first column
#> k #> A 3 #> B 6 #> C 1 #> D 0 #> E 1 #> F 7 #> G 1 #> H 2 #> I 3 #> J 1
## 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
#> A B C D E F G H I J #> 62 49 45 45 52 52 33 33 39 44
## This allows to restore the source data A2 <- as_count(B) all(A1 == A2)
#> [1] TRUE