rel_start: Rescale variables to start values by group

View source: R/convenience.R

rel_startR Documentation

Rescale variables to start values by group

Description

Convenience wrapper of dplyr::group_by and dplyr::mutate to scale variables, especially time-series, by series start values

Usage

rel_start(df, col_vars, group_vars)

Arguments

df

data.frame

col_vars

variable names (quoted or unquoted) to rescale to initial values

group_vars

variable names (quoted or unquoted) to group col_vars by

Value

data.frame with all original data and new rel_ columns for each rescaled variable

Examples

test_df <- data.frame(grp = rep(1:3, each = 10)
, val = rep(10:1, times = 3))


test_df %>%
  rel_start(col_vars = val, group_vars = grp) %>%
  print(n = 30)

test_df %>%
  rel_start(col_vars = "val", group_vars = "grp") %>%
  print(n = 30)

mikeroswell/ratioScales documentation built on July 18, 2024, 6:36 p.m.