Skip to contents

Retrieves or defines the row sums (before closure).

Usage

totals(object)

totals(object) <- value

# S4 method for class 'CompositionMatrix'
totals(object)

# S4 method for class 'LogRatio'
totals(object)

# S4 method for class 'CompositionMatrix'
totals(object) <- value

Arguments

object

An object from which to get or set totals.

value

A possible value for the totals of x.

Value

  • totals() <- value returns an object of the same sort as x with the new row sums assigned.

  • totals() returns the row sums of x.

See also

Other mutators: groups(), mutators

Author

N. Frerebeau

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
totals(B)
#>  [1] 239 328 390 142 171 234 168 189 214 137 316 241 284 291 241 252 217 201 382
#> [20] 140

## 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.06694561 0.15481172 0.13807531 0.25104603 0.38912134
#> S2 0.29268293 0.02134146 0.19512195 0.24085366 0.25000000
#> S3 0.23076923 0.23076923 0.18717949 0.11538462 0.23589744
#> S4 0.08450704 0.12676056 0.08450704 0.10563380 0.59859155
#> S5 0.40935673 0.39766082 0.02923977 0.05263158 0.11111111
#> S6 0.37606838 0.37179487 0.16239316 0.01282051 0.07692308