Skip to contents

An S4 class to represent compositional data.

Slots

totals

A numeric vector to store the absolute row sums (before the closure of the compositions).

groups

A factor vector to store the group names.

Note

This class inherits from matrix.

Coerce

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

as.data.frame(x)

Coerces to a data.frame.

Subset

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

x[i, j]

Extract parts of a matrix (see [).

Author

N. Frerebeau

Examples

## Data from Aitchison 1986
data("hongite")

## Coerce to compositional data
coda <- as_composition(hongite)

## codaccess
dim(coda) # Get the matrix dimensions
#> [1] 25  5
row(coda) # Get the row indexes
#>       [,1] [,2] [,3] [,4] [,5]
#>  [1,]    1    1    1    1    1
#>  [2,]    2    2    2    2    2
#>  [3,]    3    3    3    3    3
#>  [4,]    4    4    4    4    4
#>  [5,]    5    5    5    5    5
#>  [6,]    6    6    6    6    6
#>  [7,]    7    7    7    7    7
#>  [8,]    8    8    8    8    8
#>  [9,]    9    9    9    9    9
#> [10,]   10   10   10   10   10
#> [11,]   11   11   11   11   11
#> [12,]   12   12   12   12   12
#> [13,]   13   13   13   13   13
#> [14,]   14   14   14   14   14
#> [15,]   15   15   15   15   15
#> [16,]   16   16   16   16   16
#> [17,]   17   17   17   17   17
#> [18,]   18   18   18   18   18
#> [19,]   19   19   19   19   19
#> [20,]   20   20   20   20   20
#> [21,]   21   21   21   21   21
#> [22,]   22   22   22   22   22
#> [23,]   23   23   23   23   23
#> [24,]   24   24   24   24   24
#> [25,]   25   25   25   25   25
col(coda, as.factor = TRUE) # Get the column indexes
#>       [,1] [,2] [,3] [,4] [,5]
#>  [1,] A    B    C    D    E   
#>  [2,] A    B    C    D    E   
#>  [3,] A    B    C    D    E   
#>  [4,] A    B    C    D    E   
#>  [5,] A    B    C    D    E   
#>  [6,] A    B    C    D    E   
#>  [7,] A    B    C    D    E   
#>  [8,] A    B    C    D    E   
#>  [9,] A    B    C    D    E   
#> [10,] A    B    C    D    E   
#> [11,] A    B    C    D    E   
#> [12,] A    B    C    D    E   
#> [13,] A    B    C    D    E   
#> [14,] A    B    C    D    E   
#> [15,] A    B    C    D    E   
#> [16,] A    B    C    D    E   
#> [17,] A    B    C    D    E   
#> [18,] A    B    C    D    E   
#> [19,] A    B    C    D    E   
#> [20,] A    B    C    D    E   
#> [21,] A    B    C    D    E   
#> [22,] A    B    C    D    E   
#> [23,] A    B    C    D    E   
#> [24,] A    B    C    D    E   
#> [25,] A    B    C    D    E   
#> Levels: A B C D E
nrow(coda) # Get the number of rows
#> [1] 25
ncol(coda) # Get the number of columns
#> [1] 5
dimnames(coda) # Get the dimension names
#> [[1]]
#>  [1] "H1"  "H2"  "H3"  "H4"  "H5"  "H6"  "H7"  "H8"  "H9"  "H10" "H11" "H12"
#> [13] "H13" "H14" "H15" "H16" "H17" "H18" "H19" "H20" "H21" "H22" "H23" "H24"
#> [25] "H25"
#> 
#> [[2]]
#> [1] "A" "B" "C" "D" "E"
#> 
rownames(coda) <- LETTERS[1:25] # Set the row names
rownames(coda) # Get the rownames
#>  [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S"
#> [20] "T" "U" "V" "W" "X" "Y"
colnames(coda) <- letters[21:25] # Set the column names
colnames(coda) # Get the column names
#> [1] "u" "v" "w" "x" "y"