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: as.data.frame(), labels(), weights()

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] 265 383 139 282 269 313 262 129 301 311 245 275 180 126 295 264 181 299 254
#> [20] 230

## 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.3433962 0.2528302 0.06792453 0.0490566 0.2867925
#> S2 0.2323760 0.2402089 0.21409922 0.1201044 0.1932115
#> S3 0.4748201 0.1151079 0.02877698 0.1870504 0.1942446
#> S4 0.0177305 0.2411348 0.12056738 0.3439716 0.2765957
#> S5 0.1635688 0.1412639 0.03717472 0.3085502 0.3494424
#> S6 0.2971246 0.0543131 0.17891374 0.1980831 0.2715655