Skip to contents

Coerce to Amounts

Usage

as_amounts(from, ...)

# S4 method for CompositionMatrix
as_amounts(from)

Arguments

from

A CompositionMatrix object.

...

Currently not used.

Value

A numeric

matrix.

See also

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

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
get_totals(B)
#>  [1] 224 213 320 230 207 302 136 229 211 286 179 222 225 106 264 280 245 264 297
#> [20] 147

## This allows to restore the source data
A2 <- as_amounts(B)

## Coerce to a data.frame
X <- data.frame(B)
head(X)
#>           V1        V2         V3          V4         V5
#> S1 0.2008929 0.3794643 0.15178571 0.214285714 0.05357143
#> S2 0.1079812 0.2065728 0.07981221 0.352112676 0.25352113
#> S3 0.2375000 0.1906250 0.16250000 0.281250000 0.12812500
#> S4 0.2739130 0.1478261 0.24347826 0.152173913 0.18260870
#> S5 0.2270531 0.3381643 0.10628019 0.009661836 0.31884058
#> S6 0.1026490 0.2086093 0.31456954 0.288079470 0.08609272