Skip to contents

Closes compositions to sum to 1.

Usage

closure(x, ...)

# S4 method for class 'numeric'
closure(x, total = 1, na.rm = TRUE)

# S4 method for class 'matrix'
closure(x, total = 1, na.rm = TRUE)

Arguments

x

A numeric vector or matrix.

...

Currently not used.

total

A numeric vector specifying the total amount to which the compositions should be closed (defaults to 1).

na.rm

A logical scalar: should missing values be removed?

Value

A numeric vector or matrix (same as x).

See also

Other operations in the simplex: arithmetic, perturbation(), powering(), scalar()

Author

N. Frerebeau

Examples

x <- as_composition(c(1, 2, 3))
y <- as_composition(c(1, 2, 1))

## Perturbation
perturbation(x, y)
#> <CompositionMatrix: 1 x 3>
#>       V1  V2    V3
#> S1 0.125 0.5 0.375
x + y
#>           V1        V2   V3
#> S1 0.4166667 0.8333333 0.75

## Powering
powering(y, 2)
#> <CompositionMatrix: 1 x 3>
#>           V1        V2        V3
#> S1 0.1666667 0.6666667 0.1666667
y * 2
#> <CompositionMatrix: 1 x 3>
#>     V1 V2  V3
#> S1 0.5  1 0.5

## Scalar product
scalar(x, y)
#> [1] 0.06646867