group: Group objects over some index by applying a function over a...

groupR Documentation

Group objects over some index by applying a function over a single dimension

Description

Array objects (e.g. FLQuant or FLQuants) are divided along a single dimnension following a given index or expression, an aggregating function is applied to each subset, and the results are joined again. Data can be added, for example, by decade or for two age groups.

Usage

group(x, FUN, ...)

## S4 method for signature 'FLQuant,function'
group(x, FUN = sum, ...)

Arguments

x

An object to group.

FUN

A function to apply along the chosen dimension, defaults to 'sum'.

...

An expression or indexing vector, named as the chosen dimension. Extra arguments to FUN can also be provided, but cannmot match names in x.

Value

A single object with reduced dimensionality.

Author(s)

Iago Mosqueira (WMR)

Examples

data(ple4)
# Add catch-at-age along two age groups, 'juv'eniles and 'adu'lts
group(catch.n(ple4), sum, age=c('juv', 'juv', rep('adu', 8)))
# An expression can use based on dimnames
group(catch.n(ple4), sum, age=age < 3)
# Mean by lustrum, by using 'year - year %% 5'
group(catch.n(ple4), mean, year = year - year %% 5)

flr/FLCore documentation built on May 4, 2024, midnight