Retrieves or defines the row sums (before closure).
Usage
get_totals(x)
set_totals(x) <- value
# S4 method for CompositionMatrix
get_totals(x)
# S4 method for CompositionMatrix
set_totals(x) <- value
Value
set_totals()
returns an object of the same sort asx
with the new row sums assigned.get_totals()
returns the row sums ofx
.
Examples
## Create a count matrix
A1 <- matrix(data = sample(1:100, 100, TRUE), nrow = 20)
## Coerce to compositions
B <- as_composition(A1)
## Row sums are internally stored before coercing to relative frequencies
get_totals(B)
#> [1] 270 345 199 373 265 259 231 198 257 333 277 309 288 321 156 235 292 286 226
#> [20] 136
## This allows to restore the source data
A2 <- as_amounts(B)
## Coerce to a data.frame
X <- data.frame(B)
head(X)
#> V1 V2 V3 V4 V5
#> S1 0.014814815 0.20000000 0.12962963 0.3333333 0.3222222
#> S2 0.159420290 0.15362319 0.28985507 0.1971014 0.2000000
#> S3 0.281407035 0.04020101 0.08542714 0.1306533 0.4623116
#> S4 0.257372654 0.19839142 0.01608579 0.2654155 0.2627346
#> S5 0.358490566 0.23018868 0.03018868 0.1735849 0.2075472
#> S6 0.003861004 0.30501931 0.10424710 0.2046332 0.3822394