Skip to contents

Coerce to Amounts

Usage

as_amounts(from, ...)

# S4 method for class 'CompositionMatrix'
as_amounts(from)

Arguments

from

A CompositionMatrix object.

...

Currently not used.

Value

A numeric matrix.

See also

Other compositional data tools: as_composition()

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] 246 344 381  84 231 240 356 195 145 283 310 277 203 198 341 153 369 261 263
#> [20] 185

## 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.10162602 0.34552846 0.3008130 0.2235772 0.02845528
#> S2 0.15406977 0.29069767 0.1947674 0.2122093 0.14825581
#> S3 0.09186352 0.17060367 0.2624672 0.2335958 0.24146982
#> S4 0.53571429 0.03571429 0.1666667 0.1190476 0.14285714
#> S5 0.35497835 0.03030303 0.2857143 0.3160173 0.01298701
#> S6 0.09583333 0.20416667 0.2875000 0.3458333 0.06666667