Skip to contents

Closes compositions to sum up to 1.

Usage

closure(object, ...)

# S4 method for numeric
closure(object, total = 1)

# S4 method for matrix
closure(object, total = 1)

Arguments

object

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

Value

A numeric vector or matrix (same as object).

Missing Values Policy

Missing values will be omitted from the calculations.

See also

Other compositional data tools: as_amounts(), as_composition()

Author

N. Frerebeau

Examples

## Create a count matrix
A1 <- matrix(data = as.numeric(sample(1:100, 100, TRUE)), nrow = 20)

## Coerce to compositions
B <- as_composition(A1)

## Row sums are internally stored before coercing to relative frequencies
## (use get_totals() to retrieve these values)
## This allows to restore the source data
A2 <- as_amounts(B)

## Coerce to an S3 data.frame
X <- data.frame(B)
head(X)
#>            col1       col2       col3       col4       col5 samples
#> row1 0.24137931 0.31034483 0.28017241 0.13362069 0.03448276    row1
#> row2 0.01069519 0.06951872 0.52406417 0.10695187 0.28877005    row2
#> row3 0.20503597 0.12589928 0.33812950 0.10791367 0.22302158    row3
#> row4 0.35684647 0.12863071 0.15767635 0.24896266 0.10788382    row4
#> row5 0.27727273 0.15454545 0.08636364 0.39545455 0.08636364    row5
#> row6 0.12236287 0.39662447 0.16033755 0.08860759 0.23206751    row6