Can be used to subset the captures data e.g. extracting all captures that meet the condition captures_status == "alive".
Arguments
- data
data frame with captures containing the following field headers: 'code', 'id_code', 'captures_status', 'age_class', 'n_captures'.
datamust not be a tibble (e.g. classtbl_df).- field
field in data to test condition (e.g. "captures_status")
- condition
value of field variable to test for (e.g. "alive")
Examples
library(sefraInputs)
library(dplyr)
data(inputsBio)
#> Warning: data set 'inputsBio' not found
assign("sp_groups", inputsBio[[1]][["sp_groups"]])
#> Error: object 'inputsBio' not found
codes <- lapply(1:20, function(x) sample(c("DIW", "PRK", "PRO"), size = sample(1:5, size = 1), replace = TRUE))
ids <- lapply(codes, function(x) sapply(x, function(i) sp_groups$id_code[which(sp_groups$code %in% i)], USE.NAMES = FALSE))
#> Error in FUN(X[[i]], ...): object 'sp_groups' not found
status <- lapply(codes, function(x) sample(c("alive", "dead", NA), size = length(x), replace = TRUE))
age_class = lapply(codes, function(x) sample(c("adult", "immature", NA), size = length(x), replace = TRUE))
captures <- lapply(codes, function(x) sample(1:10, size = length(x), replace = TRUE))
x <- data.frame(id_fishery_group = rep(1:2, each = 10), id_period = rep(1:3, length = 20),
code = I(codes), id_code = I(ids), captures_status = I(status), age_class = I(age_class), n_captures = I(captures))
#> Error: object 'ids' not found
x %>% filter_captures(., field = "captures_status", condition = "alive")
#> Error: object 'x' not found
x %>% filter_captures(., field = "captures_status", condition = "dead")
#> Error: object 'x' not found