Learn R Programming

nexus (version 0.3.0)

as_composition: Coerce to a Closed Compositional Matrix

Description

Coerces an object to a CompositionMatrix object.

Usage

as_composition(from, ...)

# S4 method for numeric as_composition(from)

# S4 method for matrix as_composition(from)

# S4 method for data.frame as_composition( from, parts = NULL, groups = NULL, verbose = getOption("nexus.verbose") )

Value

A CompositionMatrix object.

Arguments

from

A matrix or data.frame to be coerced.

...

Currently not used.

parts

A vector giving the index of the column to be used a compositional parts. If NULL (the default), all double columns will be used.

groups

An integer giving the index of the column to be used to group the samples. If NULL (the default), no grouping is stored.

verbose

A logical scalar: should R report extra information on progress?

Author

N. Frerebeau

Details

See vignette("nexus").

See Also

Other compositional data tools: as_amounts()

Examples

Run this code
## 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)

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

## Coerce to a data.frame
X <- data.frame(B)
head(X)

Run the code above in your browser using DataLab