Takes a numeric vector and will return the velocity 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 velocity of that vector. The velocity of a time series is computed by taking the first difference, so $$x_t - x_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_acceleration_augment()
,
ts_growth_rate_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_velocity_augment(data_tbl, b)
#> # A tibble: 10 × 4
#> date_col a b velocity_b
#> <date> <dbl> <dbl> <dbl>
#> 1 2021-01-01 1.51 0.416 NA
#> 2 2021-02-01 -2.59 0.124 -0.293
#> 3 2021-03-01 0.754 0.634 0.511
#> 4 2021-04-01 1.53 0.321 -0.313
#> 5 2021-05-01 -0.254 0.579 0.258
#> 6 2021-06-01 0.318 0.222 -0.357
#> 7 2021-07-01 -0.742 0.869 0.647
#> 8 2021-08-01 1.03 0.231 -0.637
#> 9 2021-09-01 -0.565 0.194 -0.0367
#> 10 2021-10-01 -0.394 0.436 0.241