Define or remove the (reference) groups to which the observations belong.
Usage
group(object, ...)
ungroup(object, ...)
# S4 method for class 'CompositionMatrix'
group(object, by, verbose = getOption("nexus.verbose"), ...)
# S4 method for class 'GroupedComposition'
group(object, by, add = FALSE, verbose = getOption("nexus.verbose"), ...)
# S4 method for class 'GroupedComposition'
ungroup(object)
# S4 method for class 'GroupedLR'
ungroup(object)
# S4 method for class 'GroupedCLR'
ungroup(object)
# S4 method for class 'GroupedALR'
ungroup(object)
# S4 method for class 'GroupedILR'
ungroup(object)
# S4 method for class 'GroupedPLR'
ungroup(object)Arguments
- object
An R object (typically, a
CompositionMatrixobject).- ...
Further parameters to be passed to internal methods.
- by
A possible value for the groups of
object(typically, acharactervector). Ifvalueis alist,interaction(by)defines the grouping.- verbose
A
logicalscalar: should R report extra information on progress?- add
A
logicalscalar. IfTRUE, add to existing groups.
Value
group()returns a grouped object of the same sort asobject.ungroup()returns an ungrouped object of the same sort asobject.
See also
Other grouping methods:
group_names(),
group_split(),
group_subset(),
is_assigned()
Examples
## Data from Aitchison 1986
data("slides")
## Coerce to compositional data
coda <- as_composition(slides, groups = 2)
## Grouping metadata
group_levels(coda)
#> [1] "A" "B" "C" "D" "E"
group_names(coda)
#> [1] "A" "B" "C" "D" "E" "A" "B" "C" "D" "E" "A" "B" "C" "D" "E" "A" "B" "C" "D"
#> [20] "E" "A" "B" "C" "D" "E"
group_indices(coda)
#> [1] 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
group_rows(coda)
#> $A
#> [1] 1 6 11 16 21
#>
#> $B
#> [1] 2 7 12 17 22
#>
#> $C
#> [1] 3 8 13 18 23
#>
#> $D
#> [1] 4 9 14 19 24
#>
#> $E
#> [1] 5 10 15 20 25
#>
group_n(coda)
#> [1] 5
group_size(coda)
#> A B C D E
#> 5 5 5 5 5
