Skip to contents

Lagged absolute change

Usage

chg_abs(x, n = 1L, fill_na = 0L)

Arguments

x

numeric vector

n

values to offset

fill_na

fill value for any NAs; default is 0

Examples

mock_provider(2020:2025) |>
  dplyr::mutate(change = chg_abs(payment), .by = group)
#> # A tibble: 12 × 4
#>     year group payment change
#>    <int> <chr>   <int>  <int>
#>  1  2020 A       12069      0
#>  2  2021 A       11920   -149
#>  3  2022 A       14274   2354
#>  4  2023 A       16829   2555
#>  5  2024 A       14928  -1901
#>  6  2025 A       11560  -3368
#>  7  2020 B       14590      0
#>  8  2021 B       15617   1027
#>  9  2022 B       16308    691
#> 10  2023 B       12783  -3525
#> 11  2024 B       12923    140
#> 12  2025 B       11874  -1049