Compare values to a baseline
baseline_compare.RdThis is used to automate comparison to baselines of various sorts without needing to do all the data wrangling by hand.
Usage
baseline_compare(
val_df,
compare_col,
base_lev,
values_col,
group_cols = NULL,
comp_fun,
...,
failmissing = TRUE,
names_to = "name",
values_to = "value",
zero_adjust = 0,
onlyzeros = FALSE
)Arguments
- val_df
dataframe of values
- compare_col
column or columns to use for grouping- needed if the baseline is one level in this column. Otherwise ignored
- base_lev
value for baseline. Can be a level in
compare_col, or a scalar, or a vector oflength(unique(val_df$compare_col)). A dataframe would be useful but not yet implemented.- values_col
column containing the values. Can be character or tidyselect or bare names, though the last are fragile.
- group_cols
character, columns to group the baselining by. Often spatial or env_obj or similar.
- comp_fun
function to use for comparison comparing the first two arguments (
differenceandrelativeincluded here as wrappers for-and/). Can be character, or list-format, (both safe) or bare name (brittle)- ...
additional arguments to
comp_fun- failmissing
logical, default TRUE. Use
tidyselect::any_ofortidyselect::all_ofwhenvalues_colorcompare_colare character. seeselectcreator()- names_to
character, as in
tidyr::pivot_longer(), used for auto-pivotting- values_to
character, as in
tidyr::pivot_longer(), used for auto-pivotting- zero_adjust
numeric (default 0) or
"auto", adjustment to data to avoid zeros by addingzero_adjusttoabs(data), e.g shifting all data away from zero, either positively or negatively. Zeros themselves are shifted up or down randomly. Used for avoiding x/0, NaN, and Inf when relativiszing and taking logs, primarily. Auto shifts by0.1*min(abs(data[data != 0])).- onlyzeros
logical, default
FALSE. Should all values be adjusted away from zero (TRUE) or only adjust zero values (FALSE)?