as_composition: Coerce to a Closed Compositional Matrix

as_compositionR Documentation

Coerce to a Closed Compositional Matrix

Description

Coerces an object to a CompositionMatrix object.

Usage

as_composition(from, ...)

## S4 method for signature 'numeric'
as_composition(from)

## S4 method for signature 'matrix'
as_composition(from)

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

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?

Details

See vignette("nexus").

Value

A CompositionMatrix object.

Author(s)

N. Frerebeau

See Also

Other compositional data tools: as_amounts()

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)

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

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

nexus documentation built on Sept. 11, 2024, 6:43 p.m.