Skip to contents

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 CompositionMatrix object).

...

Further parameters to be passed to internal methods.

by

A possible value for the groups of object (typically, a character vector). If value is a list, interaction(by) defines the grouping.

verbose

A logical scalar: should R report extra information on progress?

add

A logical scalar. If TRUE, add to existing groups.

Value

  • group() returns a grouped object of the same sort as object.

  • ungroup() returns an ungrouped object of the same sort as object.

Details

Missing values (NA) can be used to specify that a sample does not belong to any group.

See also

Other grouping methods: group_extract(), group_metadata, group_split()

Author

N. Frerebeau

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_length(coda)
#> [1] 5

group_size(coda)
#> A B C D E 
#> 5 5 5 5 5