An S4 class to represent a relative frequency matrix.

Details

To ensure data integrity, a FrequencyMatrix can only be created by coercion from a CountMatrix (see examples).

Slots

total

A numeric vector.

Get and set

In the code snippets below, x is a FrequencyMatrix object.

get_id(x)

Get the unique ID of x.

get_totals(x)

Get the row sums (counts) of x.

Matrix ID

When a matrix is first created, an identifier is generated (UUID v4). This ID is preserved when coercing to another class. Thus, the object ID is unique within the same class, but two objects of different classes can have the same ID. This makes it possible to identify objects representing the same initial data and associate them with the results of specific computations (e. g. seriation).

Access

In the code snippets below, x is a *Matrix object.

dim(x)

Returns the dimension of x.

nrow(x)

Returns the number of rows present in x.

ncol(x)

Returns the number of columns present in x.

dimnames(x), dimnames(x) <- value

Retrieves or sets the row dimnames of x according to value.

rownames(x), rownames(x) <- value

Retrieves or sets the row names of x according to value.

colnames(x), colnames(x) <- value

Retrieves or sets the column names of x according to value.

Subset

In the code snippets below, x is a *Matrix object.

x[i, j]

Extracts elements selected by subscripts i and j. 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. Returns an object of the same class as x.

x[[i]]

Extracts informations from a slot selected by subscript i. i should be one of "id" or NULL.

See also

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] "2cb5983f-834c-418d-b99f-579478019e40"
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] "2cb5983f-834c-418d-b99f-579478019e40"
A1[, ] # Get all values
#> k l m n o p q r s t #> A 8 4 2 1 6 3 10 3 1 8 #> B 1 2 2 0 9 6 4 3 0 2 #> C 6 0 5 10 6 10 9 7 5 0 #> D 3 1 5 4 9 9 2 3 5 1 #> E 8 4 2 1 4 9 3 2 7 3 #> F 8 0 6 3 7 9 7 6 8 8 #> G 9 8 2 8 2 0 6 4 8 3 #> H 10 10 5 7 6 2 7 2 7 7 #> I 1 6 1 9 0 4 9 1 8 8 #> J 10 0 6 10 3 10 0 8 8 9
A1[1, ] # Get the first row
#> k l m n o p q r s t #> 8 4 2 1 6 3 10 3 1 8
A1[c("A", "B", "C"), ] # Get the first three rows
#> k l m n o p q r s t #> A 8 4 2 1 6 3 10 3 1 8 #> B 1 2 2 0 9 6 4 3 0 2 #> C 6 0 5 10 6 10 9 7 5 0
A1[c("A", "B", "C"), 1] # Get the first three rows of the first column
#> A B C #> 8 1 6
A1[, 1, drop = FALSE] # Get the first column
#> k #> A 8 #> B 1 #> C 6 #> D 3 #> E 8 #> F 8 #> G 9 #> H 10 #> I 1 #> J 10
## 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 #> 46 29 58 42 43 62 50 63 47 64
## This allows to restore the source data A2 <- as_count(B) all(A1 == A2)
#> [1] TRUE