Skip to contents

Creates a baseline column in several different ways. Helper for baseline_compare() but useful elsewhere too

Usage

create_base(
  val_df,
  compare_col,
  base_lev,
  values_col,
  group_cols = NULL,
  failmissing = TRUE,
  names_to,
  values_to
)

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 of length(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.

failmissing

logical, default TRUE. Use tidyselect::any_of or tidyselect::all_of when values_col or compare_col are character. see selectcreator()

names_to

character, as in tidyr::pivot_longer(), used for auto-pivotting

values_to

character, as in tidyr::pivot_longer(), used for auto-pivotting

Value

a tibble matching val_df (or a long version thereof if val_df is wide), with an added column for the reference level (named ref_values_col)