Coerce to a Data Frame
Usage
# S4 method for class 'CompositionMatrix'
as.data.frame(x, row.names = rownames(x), optional = FALSE, ...)
# S4 method for class 'GroupedComposition'
as.data.frame(
x,
row.names = rownames(x),
optional = FALSE,
...,
group_var = ".group"
)
# S4 method for class 'LogRatio'
as.data.frame(x, row.names = rownames(x), optional = FALSE, ...)
# S4 method for class 'GroupedLogRatio'
as.data.frame(
x,
row.names = rownames(x),
optional = FALSE,
...,
group_var = ".group"
)
# S4 method for class 'OutlierIndex'
as.data.frame(x, row.names = rownames(x), optional = FALSE, ...)
Arguments
- x
An R object (typically, a
CompositionMatrix
object).- row.names
A
character
vector giving the row names for the data frame, orNULL
.- optional
A
logical
scalar: should the names of the variables in the data frame be checked? IfFALSE
then the names of the variables in the data frame are checked to ensure that they are syntactically valid variable names and are not duplicated.- ...
Currently not used.
- group_var
A
character
string specifying the name of the column to create for group attribution.
Value
A data.frame
.
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)
#> [1] 224 213 320 230 207 302 136 229 211 286 179 222 225 106 264 280 245 264 297
#> [20] 147
## This allows to restore the source data
A2 <- as_amounts(B)
## Coerce to a data.frame
X <- as.data.frame(B)
head(X)
#> V1 V2 V3 V4 V5
#> S1 0.2008929 0.3794643 0.15178571 0.214285714 0.05357143
#> S2 0.1079812 0.2065728 0.07981221 0.352112676 0.25352113
#> S3 0.2375000 0.1906250 0.16250000 0.281250000 0.12812500
#> S4 0.2739130 0.1478261 0.24347826 0.152173913 0.18260870
#> S5 0.2270531 0.3381643 0.10628019 0.009661836 0.31884058
#> S6 0.1026490 0.2086093 0.31456954 0.288079470 0.08609272