Captures are stored as list items per fishing event. To extract, each event is unlisted, matched to the species or species group and summed.
Usage
aggregate_captures(data, strata, lookup = list(), verbose = FALSE)Value
An object of class class(data) with total captures (n_captures) per species groupings from lookup (group). group takes it's values from the names of the lookup argument. The aggregated captures are (optionally) grouped by the variables in the strata argument. Species groups with no captures are included in the returned object with n_captures = 0, for each combination of variables in the strata argument if provided.
Examples
library(sefraInputs)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
data(inputsBio)
#> Warning: data set 'inputsBio' not found
# examples with named vector of species codes
assign("species", inputsBio[[1]][['sp_codes']]$code)
#> Error: object 'inputsBio' not found
names(species) <- species
#> Error: object 'species' not found
codes <- lapply(1:20, function(x) sample(species, size = sample(1:5, size = 1)))
#> Error in FUN(X[[i]], ...): object 'species' not found
captures <- lapply(codes, function(x) sample(1:10, size = length(x)))
#> Error: object 'codes' not found
x <- data.frame(id_fishery_group = rep(1:2, each = 10), id_period = rep(1:3, length = 20), code = I(codes), n_captures = I(captures))
#> Error: object 'codes' not found
x %>% aggregate_captures(., lookup = species)
#> Error: object 'x' not found
x %>% aggregate_captures(., strata = "id_fishery_group", lookup = species)
#> Error: object 'x' not found
x %>% aggregate_captures(., strata = c("id_fishery_group", "id_period"), lookup = species)
#> Error: object 'x' not found
# example with unnamed vector of species codes
names(species) <- NULL
#> Error: object 'species' not found
x %>% aggregate_captures(., lookup = species)
#> Error: object 'x' not found