I am looking for a function that fills my NA values in a data.table column with a "trend" of the previous values. I know that there is the function: na.locf() But this function only uses the last available value and forwards it into the future. What I want is that the specific function looks a the "trend", so at the evolution of more than just the last available values und writes this trend into the future.
data
year,V1
2020,1
2021,1.5
2023,2
2024,2.5
2025,3
2026,NA
2027,NA
2028,NA
2029,NA
2030,NA
expected output:
data
year,V1
2020,1
2021,1.5
2023,2
2024,2.5
2025,3
2026,3.5
2027,4
2028,4.5
2029,5
2030,5.5
Related but not a duplicate of these posts: