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

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

## Arguments

data A data vector. An integer value giving the desired number of rows. An integer value giving the desired number of columns. A logical scalar: should the matrix be filled by rows? If FALSE (the default) the matrix is filled by columns. A list of length 2 giving the row and column names respectively. If NULL (the default) dimension names will be created.

## Slots

totals

A numeric vector giving the absolute row sums.

## Access

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

length(x)

Returns the length of x.

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, ..., drop]

Extracts elements selected by subscripts i and j. Indices are numeric 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 dimnames of the object. 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.

as_abundance

Other matrix: CountMatrix-class, DataMatrix-class, GenericMatrix-class, IncidenceMatrix-class, OccurrenceMatrix-class, SimilarityMatrix-class, StratigraphicMatrix-class, coerce()

N. Frerebeau

## Examples

## 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
#> [1] 20  5row(B) # 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   20col(B, as.factor = TRUE) # Get the column indexes
#>       [,1] [,2] [,3] [,4] [,5]
#>  [1,] col1 col2 col3 col4 col5
#>  [2,] col1 col2 col3 col4 col5
#>  [3,] col1 col2 col3 col4 col5
#>  [4,] col1 col2 col3 col4 col5
#>  [5,] col1 col2 col3 col4 col5
#>  [6,] col1 col2 col3 col4 col5
#>  [7,] col1 col2 col3 col4 col5
#>  [8,] col1 col2 col3 col4 col5
#>  [9,] col1 col2 col3 col4 col5
#> [10,] col1 col2 col3 col4 col5
#> [11,] col1 col2 col3 col4 col5
#> [12,] col1 col2 col3 col4 col5
#> [13,] col1 col2 col3 col4 col5
#> [14,] col1 col2 col3 col4 col5
#> [15,] col1 col2 col3 col4 col5
#> [16,] col1 col2 col3 col4 col5
#> [17,] col1 col2 col3 col4 col5
#> [18,] col1 col2 col3 col4 col5
#> [19,] col1 col2 col3 col4 col5
#> [20,] col1 col2 col3 col4 col5
#> Levels: col1 col2 col3 col4 col5nrow(B) # Get the number of rows
#> [1] 20ncol(B) # Get the number of columns
#> [1] 5dimnames(B) # Get the dimension names
#> [[1]]
#>  [1] "row1"  "row2"  "row3"  "row4"  "row5"  "row6"  "row7"  "row8"  "row9"
#> [10] "row10" "row11" "row12" "row13" "row14" "row15" "row16" "row17" "row18"
#> [19] "row19" "row20"
#>
#> [[2]]
#> [1] "col1" "col2" "col3" "col4" "col5"
#> rownames(B) <- LETTERS[1:20] # Set the row names
rownames(B) # 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"colnames(B) <- letters[21:25] # Set the column names
colnames(B) # Get the column names
#> [1] "u" "v" "w" "x" "y"
## Subset
B[[1, 1]] # Get the first value
#> [1] 1B[, ] # Get all values
#> <CountMatrix: 20 x 5>
#>    u  v  w x y
#> A  1  6  1 3 8
#> B  5  6  2 1 0
#> C  6  7  2 5 6
#> D  9  1  0 4 3
#> E  5  7  9 9 7
#> F  4  8  6 9 9
#> G  6  2  4 2 7
#> H  2  8  3 3 6
#> I  0 10  0 5 8
#> J  4  5  2 1 8
#> K  0  8  6 8 9
#> L  5  4  0 4 8
#> M  0  2  5 2 2
#> N  0  1 10 1 8
#> O  1  6  6 4 2
#> P  4  3 10 9 0
#> Q  6 10  9 3 6
#> R 10  3  7 2 4
#> S  0  1  5 7 8
#> T  3  8  0 3 3B[1, ] # Get the first row
#> [1] 1 6 1 3 8B[, 1] # Get the first column
#>  [1]  1  5  6  9  5  4  6  2  0  4  0  5  0  0  1  4  6 10  0  3B[c("A", "B", "C"), ] # Get the first three rows
#> <CountMatrix: 3 x 5>
#>   u v w x y
#> A 1 6 1 3 8
#> B 5 6 2 1 0
#> C 6 7 2 5 6B[c("D", "E", "F"), 1, drop = FALSE] # Get 3 rows of the first column
#> <CountMatrix: 3 x 1>
#>   u
#> D 9
#> E 5
#> F 4