An S4 class to represent a relative frequency matrix (i.e. the fraction of times a given datum occurs in a dataset).

## Slots

totals

A numeric vector.

## 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.

## Get and set

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

get_id(x)

Get the ID of x.

get_dates(x) and set_dates(x) <- value

Get or set the dates of x.

get_coordinates(x) and set_coordinates(x) <- value

Get or set the geographical coordinates of x.

## 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 a single element selected by subscript i.

NumericMatrix

Other matrix: CountMatrix-class, IncidenceMatrix-class, LogicalMatrix-class, Matrix-class, NumericMatrix-class, OccurrenceMatrix-class, SimilarityMatrix-class, StratigraphicMatrix-class, coerce

## Examples

## Create a count data matrix
A1 <- CountMatrix(data = sample(0:10, 100, TRUE), nrow = 10, ncol = 10)

## Access
get_id(A1)#> [1] "21fde598-c02e-460a-b75b-c1e86723e4d2"dim(A1) # Get the matrix dimensions#> [1] 10 10colnames(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] 6A1[, ] # Get all values#>   k  l  m n  o p q r  s  t
#> A 6  6  8 1  8 6 2 1  0  6
#> B 4 10  5 0  1 9 8 5  5  6
#> C 5 10 10 3  4 2 1 6  0  7
#> D 3  4  6 7  7 5 7 9  0  1
#> E 5  4  4 5  0 3 0 5  1  7
#> F 8  1  5 0  2 9 0 4  4  8
#> G 4  5  8 5 10 0 6 6  6  2
#> H 4  3  5 1  9 6 5 2 10  8
#> I 7  1  9 2  2 5 8 0  0 10
#> J 1  2  4 0  1 5 9 4  3  5A1[1, ] # Get the first row#> k l m n o p q r s t
#> 6 6 8 1 8 6 2 1 0 6 A1[c("A", "B", "C"), ] # Get the first three rows#>   k  l  m n o p q r s t
#> A 6  6  8 1 8 6 2 1 0 6
#> B 4 10  5 0 1 9 8 5 5 6
#> C 5 10 10 3 4 2 1 6 0 7A1[c("A", "B", "C"), 1] # Get the first three rows of the first column#> A B C
#> 6 4 5 A1[, 1, drop = FALSE] # Get the first column#>   k
#> A 6
#> B 4
#> C 5
#> D 3
#> E 5
#> F 8
#> G 4
#> H 4
#> I 7
#> 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
#> 44 53 48 49 34 41 52 53 44 34 ## 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)