Add age dimensions to g3_stock classes

g3s_age(inner_stock, minage, maxage)

g3s_agegroup(inner_stock, agegroups)

Arguments

inner_stock

A g3_stock that we extend with an age dimension

minage

Minimum age to store, integer.

maxage

Maximum age to store, integer.

agegroups

(optionally named) list of vectors of ages, grouping them together.

Value

g3s_age

A g3_stock with an additional 'age' dimension.

When iterating over the stock, iterate over each age in turn, age will be set to the current integer age.

When intersecting with another stock, only do anything if age is betweem minage and maxage.

If an age dimension already exists, it is redefined with new parameters.

g3s_agegroup

A g3_stock with an additional 'age' dimension.

When iterating over the stock, iterate over each agegroup in turn, age will be set to the first age in the group.

When intersecting with another stock, only do anything if age is part of one of the groups.

Examples

library(magrittr)

# Define a stock with 3 lengthgroups and 3 ages
stock <- g3_stock('name', c(1, 10, 100)) %>%
    g3s_age(5, 10)

# Use stock_instance to see what the array would look like
g3_stock_instance(stock)
#>          age
#> length    age5 age6 age7 age8 age9 age10
#>   1:10      NA   NA   NA   NA   NA    NA
#>   10:100    NA   NA   NA   NA   NA    NA
#>   100:Inf   NA   NA   NA   NA   NA    NA

# Define a stock that groups age into "young" and "old"
stock <- g3_stock('name', c(1, 10, 100)) %>%
    g3s_agegroup(list(
        young = 5:7,
        old = 8:10))

# Use stock_instance to see what the array would look like
g3_stock_instance(stock)
#>          age
#> length    young old
#>   1:10       NA  NA
#>   10:100     NA  NA
#>   100:Inf    NA  NA