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

Other mutators: labels(), weights()

Author

N. Frerebeau

Examples

## Create a count matrix
A1 <- matrix(data = sample(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] 226 221 227 308 234 267 310 350 254 321 188 315 268 341 234 212 262 175 208
#> [20] 253

## 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.05752212 0.01327434 0.25663717 0.3893805 0.2831858
#> S2 0.11764706 0.09954751 0.08144796 0.3257919 0.3755656
#> S3 0.05286344 0.24669604 0.14096916 0.4229075 0.1365639
#> S4 0.06168831 0.12662338 0.30844156 0.2694805 0.2337662
#> S5 0.39743590 0.02991453 0.21794872 0.1068376 0.2478632
#> S6 0.08239700 0.21348315 0.24344569 0.2808989 0.1797753