Takes a numeric vector and will return the acceleration of that vector.
Arguments
- .data
The data being passed that will be augmented by the function.
- .value
This is passed
rlang::enquo()
to capture the vectors you want to augment.- .names
The default is "auto"
Details
Takes a numeric vector and will return the acceleration of that vector. The acceleration of a time series is computed by taking the second difference, so $$(x_t - x_t1) - (x_t - x_t1)_t1$$
This function is intended to be used on its own in order to add columns to a tibble.
See also
Other Augment Function:
ts_growth_rate_augment()
,
ts_velocity_augment()
Examples
suppressPackageStartupMessages(library(dplyr))
len_out = 10
by_unit = "month"
start_date = as.Date("2021-01-01")
data_tbl <- tibble(
date_col = seq.Date(from = start_date, length.out = len_out, by = by_unit),
a = rnorm(len_out),
b = runif(len_out)
)
ts_acceleration_augment(data_tbl, b)
#> # A tibble: 10 × 4
#> date_col a b acceleration_b
#> <date> <dbl> <dbl> <dbl>
#> 1 2021-01-01 0.443 0.486 NA
#> 2 2021-02-01 -1.07 0.0806 NA
#> 3 2021-03-01 -0.498 0.223 0.548
#> 4 2021-04-01 1.38 0.309 -0.0565
#> 5 2021-05-01 -1.01 0.359 -0.0354
#> 6 2021-06-01 0.0423 0.414 0.00447
#> 7 2021-07-01 0.810 0.522 0.0539
#> 8 2021-08-01 -1.09 0.586 -0.0449
#> 9 2021-09-01 0.254 0.826 0.177
#> 10 2021-10-01 0.342 0.748 -0.319