| 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  | 
| ... | Currently not used. | 
| codes | An  | 
| samples | An  | 
| groups | An  | 
| auto | A  | 
| verbose | A  | 
Details
The CompositionMatrix class has special slots:
-  codesfor laboratory codes,
-  samplesfor repeated measurements/observation,
-  groupsto group data by site/area.
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)