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 object.

Value

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

  • totals() returns the row sums of object.

See also

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] 343 391 327 280 267 155 303 242 253 144 236 288  86 301 145 354 157 284 292
#> [20]  96

## 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.28279883 0.22157434 0.02915452 0.24198251 0.2244898
#> S2 0.17135550 0.19181586 0.22250639 0.23529412 0.1790281
#> S3 0.26911315 0.01834862 0.15596330 0.25382263 0.3027523
#> S4 0.06071429 0.20714286 0.28928571 0.08928571 0.3535714
#> S5 0.25093633 0.14232210 0.24719101 0.11985019 0.2397004
#> S6 0.39354839 0.25161290 0.18064516 0.12258065 0.0516129