Datasets for which this package has been developed, typically contain measurements of observations. Absence is often not reported explicitly (e.g. there exists no record of a species that is not observed in a plot), while it can be important to include these zero values in an analysis (e.g. mean coverage per species in a certain forest reserve; mean stem number per diameter class in a forest reserve). This function automatically adds missing combinations with value zero to the dataset for each combination of values of the variables given in `comb_vars` (within each value of `grouping_vars`). All variables that are not mentioned in `comb_vars` or `grouping_vars`, are considered to be numerical variables and will get value 0 (zero). Note that if a certain value is not present in the dataset (or in one of the subsets defined by `grouping_vars`), it will not be added automatically; at least one record should be added manually for this value (e.g. a plot or diameterclass that doesn't exist in the given dataset, but has to be included in the output).

add_zeros(dataset, comb_vars, grouping_vars)

Arguments

dataset

data.frame in which records should be added

comb_vars

variables (given as a vector of strings) of which all combinations of their values should have a record in the dataset.

grouping_vars

one or more variables for which the combination of values of the variables given in `comb_vars` should be made for each value, e.g. if grouping_vars = "forest_reserve" and comb_vars = c("plot", "species"), all combinations of the values in "plot" and "species" are made within each value of "forest_reserve".

Value

dataframe based on `dataset` to which records are added with value 0 (zero) for each measurement.

Examples

if (FALSE) {
#change path before running
library(forrescalc)
library(tidyverse)
dendro_by_plot_species <-
  read_forresdat(tablename = "dendro_by_plot_species", repo_path = "C:/gitrepo/forresdat") %>%
  select(-year, -plottype)
add_zeros(
  dataset = dendro_by_plot_species,
  comb_vars = c("plot_id", "species"),
  grouping_vars = c("forest_reserve", "period")
)
}