Skip to contents

Calculate Lagged Metrics

Usage

change(df, cols, csm = NULL)

Arguments

df

data frame

cols

numeric columns to calculate absolute/relative change & rate of return

csm

numeric cols to calculate cumulative sum for

Examples

fuimus:::provider_data(2020:2025) |>
  dplyr::group_by(group) |>
  change(net_payment, csm = c("payment", "_chg"))
#> # A tibble: 12 × 8
#>     year group net_payment net_payment_chg net_payment_pct net_payment_ror
#>    <int> <chr>       <int>           <int>           <dbl>           <dbl>
#>  1  2020 A           15292               0          0                1    
#>  2  2021 A           15526             234          0.0153           1.02 
#>  3  2022 A           16603            1077          0.0694           1.07 
#>  4  2023 A           10484           -6119         -0.369            0.631
#>  5  2024 A           12606            2122          0.202            1.20 
#>  6  2025 A           11475           -1131         -0.0897           0.910
#>  7  2020 B           18165               0          0                1    
#>  8  2021 B           12244           -5921         -0.326            0.674
#>  9  2022 B           14612            2368          0.193            1.19 
#> 10  2023 B           19982            5370          0.368            1.37 
#> 11  2024 B           14172           -5810         -0.291            0.709
#> 12  2025 B           19089            4917          0.347            1.35 
#> # ℹ 2 more variables: net_payment_csm <int>, net_payment_chg_csm <int>