spsanderson / healthyR.ts

A time-series companion package to healthyR
https://www.spsanderson.com/healthyR.ts/
Other
18 stars 3 forks source link

Update `ts_vva_plt()` #516

Closed spsanderson closed 1 week ago

spsanderson commented 1 month ago

Currently ts_vva_plt() has the following code:

data_diff_tbl <- data_tbl %>%
    timetk::tk_augment_differences(.value = {{value_col_var_expr}}, .differences = 1) %>%
    timetk::tk_augment_differences(.value = {{value_col_var_expr}}, .differences = 2) %>%

It needs to be as follows:

data_diff_tbl <- data_tbl |>
  timetk::tk_augment_differences(.value = {{value_col_var_expr}}, .lags = c(1, 2)) |>
  dplyr::rename(velocity = dplyr::contains("_lag1")) |>
  dplyr::rename(acceleration = dplyr::contains("_lag2")) |>
  tidyr::pivot_longer(-{{date_col_var_expr}}) |>
  dplyr::mutate(name = stringr::str_to_title(name)) |>
  dplyr::mutate(name = forcats::as_factor(name))