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: as.data.frame(), 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] 120 249 275 232 305 386 204  55 378 261 309 283 328 226 314 327 327 172 238
#> [20] 190

## This allows to restore the source data
A2 <- as_amounts(B)

## Coerce to a data.frame
X <- as.data.frame(B)
head(X)
#>            V1         V2        V3         V4        V5
#> S1 0.09166667 0.09166667 0.3166667 0.29166667 0.2083333
#> S2 0.19678715 0.12449799 0.1566265 0.27710843 0.2449799
#> S3 0.30545455 0.24727273 0.2545455 0.04727273 0.1454545
#> S4 0.26724138 0.24568966 0.1336207 0.07758621 0.2758621
#> S5 0.24590164 0.21311475 0.3016393 0.08196721 0.1573770
#> S6 0.21761658 0.11917098 0.2098446 0.21761658 0.2357513