Skip to contents

Lagged rate of return

Usage

rate_of_return(df, col, n = 1, fill_na = 1L)

Arguments

df

data frame

col

numeric column

n

<int> values to offset

fill_na

<int> fill value for any NAs; default is 1

Examples

fuimus:::provider_data(2020:2025) |>
  dplyr::group_by(group) |>
  rate_of_return(net_payment)
#> # A tibble: 12 × 4
#>     year group net_payment net_payment_ror
#>    <int> <chr>       <int>           <dbl>
#>  1  2020 A           13091           1    
#>  2  2021 A           10877           0.831
#>  3  2022 A           19036           1.75 
#>  4  2023 A           10929           0.574
#>  5  2024 A           14095           1.29 
#>  6  2025 A           16278           1.15 
#>  7  2020 B           18944           1    
#>  8  2021 B           18779           0.991
#>  9  2022 B           19181           1.02 
#> 10  2023 B           12721           0.663
#> 11  2024 B           14582           1.15 
#> 12  2025 B           19055           1.31