Calculate Lagged Metrics
Examples
mock_provider(2020:2025) |>
dplyr::group_by(group) |>
change(payment, csm = c("payment", "_chg"))
#> # A tibble: 12 × 8
#> year group payment payment_chg payment_pct payment_ror payment_csm
#> <int> <chr> <int> <int> <dbl> <dbl> <int>
#> 1 2020 A 15292 0 0 1 15292
#> 2 2021 A 15526 234 0.0153 1.02 30818
#> 3 2022 A 16603 1077 0.0694 1.07 47421
#> 4 2023 A 10484 -6119 -0.369 0.631 57905
#> 5 2024 A 12606 2122 0.202 1.20 70511
#> 6 2025 A 11475 -1131 -0.0897 0.910 81986
#> 7 2020 B 18165 0 0 1 18165
#> 8 2021 B 12244 -5921 -0.326 0.674 30409
#> 9 2022 B 14612 2368 0.193 1.19 45021
#> 10 2023 B 19982 5370 0.368 1.37 65003
#> 11 2024 B 14172 -5810 -0.291 0.709 79175
#> 12 2025 B 19089 4917 0.347 1.35 98264
#> # ℹ 1 more variable: payment_chg_csm <int>