Coerces an object to a CompositionMatrix
object.
Arguments
- from
A
matrix
ordata.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. IfNULL
(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. IfNULL
(the default), no grouping is stored.- auto
A
logical
scalar: try to automatically detectcodes
,samples
andgroups
columns?- verbose
A
logical
scalar: should R report extra information on progress?
Value
A CompositionMatrix
object.
Details
The CompositionMatrix
class has special slots:
codes
for laboratory codes,samples
for repeated measurements/observation,groups
to 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")
.
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)
#> [1] 245 264 258 162 253 285 223 369 255 279 190 246 344 381 84 231 240 356 195
#> [20] 145
## This allows to restore the source data
A2 <- as_amounts(B)
## Coerce to a data.frame
X <- data.frame(B)
head(X)
#> V1 V2 V3 V4 V5
#> S1 0.13469388 0.1673469 0.15918367 0.33877551 0.2000000
#> S2 0.13636364 0.3106061 0.04166667 0.21212121 0.2992424
#> S3 0.02713178 0.3643411 0.16279070 0.20155039 0.2441860
#> S4 0.14197531 0.1172840 0.24691358 0.35185185 0.1419753
#> S5 0.34782609 0.3003953 0.05928854 0.06719368 0.2252964
#> S6 0.11929825 0.1789474 0.28771930 0.30526316 0.1087719