Validate a data frame with predator/prey mass ratio observations
Source:R/validate.R
validate_ppmr_data.RdThe data frame needs to have the columns "species", "w_pred", "w_prey" and
"n_prey". The function adds a log_ppmr column to the data frame with the
logarithm of the predator/prey mass ratio.
Value
Valid ppmr data frame with columns "species", "w_pred", "w_prey", "n_prey" and "log_ppmr" and rows for the specified species.
Details
If a log_ppmr column already exists, it is overwritten and a warning is
issued if discrepancies were found. A warning is also issued if any prey
is heavier than the predator.
See also
Other validation functions:
validate_fit(),
validate_weighted_observations()
Examples
# Validate the barnes_data dataset
valid_data <- validate_ppmr_data(barnes_data)
head(valid_data)
#> # A tibble: 6 × 5
#> species w_pred w_prey n_prey log_ppmr
#> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 Atlantic bluefin tuna 61666 3.51 1 9.77
#> 2 Atlantic bluefin tuna 61666 3.51 1 9.77
#> 3 Atlantic bluefin tuna 61666 3.51 1 9.77
#> 4 Atlantic bluefin tuna 61666 4.63 1 9.50
#> 5 Atlantic bluefin tuna 61666 4.63 1 9.50
#> 6 Atlantic bluefin tuna 61666 4.63 1 9.50
# Validate and filter to a single species
cod_data <- validate_ppmr_data(barnes_data, species = "Atlantic cod")
nrow(cod_data)
#> [1] 2518