as_composition {nexus}R 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,
  codes = NULL,
  samples = NULL,
  groups = NULL,
  auto = getOption("nexus.autodetect"),
  verbose = getOption("nexus.verbose")
)

Arguments

from

A matrix or data.frame to be coerced.

...

Currently not used.

codes

An integer giving the index of the column to be used as laboratory codes (unique identifiers).

samples

An integer giving the index of the column to be used for sample identification: allows duplicates to identify replicated measurements. If NULL (the default), row names will be used as sample IDs.

groups

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

auto

A logical scalar: try to automatically detect codes, samples and groups columns?

verbose

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

Details

The CompositionMatrix class has special slots:

When coercing a data.frame to a CompositionMatrix object, an attempt is made to automatically assign values to these slots by mapping column names (case insensitive, plural insensitive). This behavior can be disabled by setting options(nexus.autodetect = FALSE) or overridden by explicitly specifying the columns to be used.

See vignette("nexus").

Value

A CompositionMatrix object.

Note

All non-numeric variable will be removed.

Author(s)

N. Frerebeau

See Also

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

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)

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

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

[Package nexus version 0.2.0 Index]