Coerce to a Data Frame
Usage
# S4 method for class 'CompositionMatrix'
as.data.frame(x, ..., group_var = ".group", group_after = 0)
# S4 method for class 'LogRatio'
as.data.frame(x, ..., group_var = ".group", group_after = 0)
# S4 method for class 'OutlierIndex'
as.data.frame(x, row.names = rownames(x), optional = FALSE, ...)Arguments
- x
An R object (typically, a
CompositionMatrixobject).- ...
Further parameters to be passed to
as.data.frame().- group_var
A
characterstring specifying the name of the column to create for group attribution (only used ifxis grouped).- group_after
An
integerspecifying a subscript, after which the newgroup_varcolumn is to be appended (only used ifxis grouped).- row.names
A
charactervector giving the row names for the data frame, orNULL.- optional
A
logicalscalar: should the names of the variables in the data frame be checked? IfFALSEthen the names of the variables in the data frame are checked to ensure that they are syntactically valid variable names and are not duplicated.
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] 179 222 225 106 264 280 245 264 297 147 212 226 251 190 248 305 140 229 193
#> [20] 340
## 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.13407821 0.48044693 0.25698324 0.03351955 0.09497207
#> S2 0.35585586 0.19369369 0.29279279 0.09909910 0.05855856
#> S3 0.34222222 0.03111111 0.11111111 0.08444444 0.43111111
#> S4 0.01886792 0.30188679 0.34905660 0.01886792 0.31132075
#> S5 0.23484848 0.20075758 0.03030303 0.24242424 0.29166667
#> S6 0.19642857 0.25000000 0.11785714 0.14285714 0.29285714
