Skip to contents

Assigns time period identifiers that are used to define years with shared catchability parameters. The time periods are defined by a look-up table (lk_definitions) that is joined to the data object using left_join. names for each fishery group are defined in lk_names. Information relating to any previously assigned time periods in the data object is removed, including both time period IDs (id_period) and names (period).

The lookup table defining time periods (lk_definitions) must have the following fields:

  • id_period - a time period identifier (integer).

Additionally, it must not have a variable named period, which is reserved for the names of the time periods.

The lookup table providing the time period names (lk_names) must have the following fields:

  • id_period - a time period identifier (integer);

  • period - the time period name (character). The name can include spaces, but should not include punctuation characters. Additionally, the name should not include LaTeX special characters, e.g., underscores (_), ampersands (&), dollar signs ($) etc.

Each record in data should match at most one defined time period, and each time group should only have one name.

Usage

assign_time_periods(data, lk_definitions, lk_names, ...)

Arguments

data

object to which time period identifiers should be added

lk_definitions

a look-up table that defines time periods. lk_definitions must include a field for time period identifiers (id_period).

lk_names

a look-up table that includes names for time periods. lk_names must include a field for time period identifiers (id_period).

...

additional arguments to left_join.

Value

An object of class class(data) including time period identifiers (id_period).

Examples

library(sefraInputs)
x <- data.frame(effort = floor(runif(10, 100, 2000)), year = sample(2011:2020, size = 10, replace = TRUE))
y <- data.frame(id_period = c(rep(1L, times = 5), rep(2L, times = 5)), year = 2011:2020)
z <- data.frame(id_period = 1:2, period = c("Pre 2015", "2016 onwards"))
assign_time_periods(x, y, z)
#> Joining with `by = join_by(year)`
#>    effort year id_period
#> 1    1183 2020         2
#> 2     737 2013         1
#> 3    1232 2012         1
#> 4     463 2017         2
#> 5    1900 2020         2
#> 6    1130 2013         1
#> 7    1134 2016         2
#> 8     629 2014         1
#> 9     948 2020         2
#> 10    805 2011         1