Getters and setters to retrieve or set parts of an object.

has_groups(x)

get_groups(x)

set_groups(x) <- value

get_samples(x)

set_samples(x) <- value

get_totals(x)

set_totals(x) <- value

# S4 method for AbundanceMatrix
has_groups(x)

# S4 method for AbundanceMatrix
get_groups(x)

# S4 method for AbundanceMatrix
get_samples(x)

# S4 method for CompositionMatrix
get_totals(x)

# S4 method for OccurrenceMatrix
get_totals(x)

# S4 method for AbundanceMatrix
set_groups(x) <- value

# S4 method for AbundanceMatrix
set_samples(x) <- value

# S4 method for CompositionMatrix
set_totals(x) <- value

Arguments

x

An object from which to get or set element(s) (typically a *Matrix object).

value

A possible value for the element(s) of x.

Value

An object of the same sort as x with the new values assigned.

See also

Other mutator: subset()

Author

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 5
row(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 20
col(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 col5
nrow(B) # Get the number of rows
#> [1] 20
ncol(B) # Get the number of columns
#> [1] 5
dimnames(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] 10
B[1] # Get the first value
#> [1] 10
B[, ] # Get all values
#> <CountMatrix: 20 x 5> #> u v w x y #> A 10 9 10 3 9 #> B 10 8 1 10 9 #> C 8 2 3 0 6 #> D 8 6 8 3 5 #> E 7 6 10 8 7 #> F 10 4 8 8 9 #> G 3 5 3 2 6 #> H 7 7 3 3 2 #> I 1 6 7 8 3 #> J 6 5 2 5 6 #> K 4 9 4 5 7 #> L 3 7 6 8 10 #> M 6 1 4 8 4 #> N 3 1 9 3 8 #> O 6 4 5 7 1 #> P 0 4 6 5 10 #> Q 0 9 10 10 1 #> R 7 2 9 7 4 #> S 10 4 9 2 4 #> T 2 10 2 6 7
B[1, , drop = FALSE] # Get the first row
#> <CountMatrix: 1 x 5> #> u v w x y #> A 10 9 10 3 9
B[, 1:3] # Get the first three column
#> <CountMatrix: 20 x 3> #> u v w #> A 10 9 10 #> B 10 8 1 #> C 8 2 3 #> D 8 6 8 #> E 7 6 10 #> F 10 4 8 #> G 3 5 3 #> H 7 7 3 #> I 1 6 7 #> J 6 5 2 #> K 4 9 4 #> L 3 7 6 #> M 6 1 4 #> N 3 1 9 #> O 6 4 5 #> P 0 4 6 #> Q 0 9 10 #> R 7 2 9 #> S 10 4 9 #> T 2 10 2