# CompositionMatrix-class: Relative Frequency Matrix In arkhe: Representation of Archaeological Data

## Description

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

## Usage

 `1` ```CompositionMatrix(data = 0, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL) ```

## Arguments

 `data` an optional data vector (including a list or `expression` vector). Non-atomic classed R objects are coerced by `as.vector` and all attributes discarded. `nrow` the desired number of rows. `ncol` the desired number of columns. `byrow` logical. If `FALSE` (the default) the matrix is filled by columns, otherwise the matrix is filled by rows. `dimnames` A `dimnames` attribute for the matrix: `NULL` or a `list` of length 2 giving the row and column names respectively. An empty list is treated as `NULL`, and a list of length one as row names. The list can be named, and the list names will be used as names for the dimensions.

## Author(s)

N. Frerebeau

`as_composition()`
Other classes: `CountMatrix-class`, `DataMatrix`, `IncidenceMatrix-class`, `OccurrenceMatrix-class`, `StratigraphicMatrix-class`, `coerce()`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24``` ```## Create an incidence (presence/absence) matrix ## Data will be coerced with as.logical() A <- IncidenceMatrix(data = sample(0:1, 100, TRUE, c(1, 1/3)), nrow = 20) ## Create a count data matrix B <- CountMatrix(data = sample(0:10, 100, TRUE), nrow = 20) ## Access dim(B) # Get the matrix dimensions row(B) # Get the row indexes col(B, as.factor = TRUE) # Get the column indexes nrow(B) # Get the number of rows ncol(B) # Get the number of columns dimnames(B) # Get the dimension names rownames(B) <- LETTERS[1:20] # Set the row names rownames(B) # Get the rownames colnames(B) <- letters[21:25] # Set the column names colnames(B) # Get the column names ## Subset B[[1, 1]] # Get the first value B[1] # Get the first value B[, ] # Get all values B[1, , drop = FALSE] # Get the first row B[, 1:3] # Get the first three column ```