How can I have a linear interpolation on the column DF in order to replace the 0 with a "weighted amount" obtained combining 0 and 0.98 for the first 11 records and 0.98 and 0.95 for the records from 13 to 23 and use 0.95 for the last two records. The idea is to have a kind of interpolation to get the monthly discount factors.
DT <- data.table(MM=c(1,2,3,4,5,6,7,8,9,10,11,12,12,14,15,16,17,18,19,20,21,22,23,24,25,26),
DF=c(1,0,0,0,0,0,0,0,0,0,0,0.98,0,0,0,0,0,0,0,0,0,0,0.95,0,0,0))
DT
Something like this, perhaps:
Steps:
approxuses theMMandDFvalues whereDF > 0, then returning interpolated values for allMM(regardless ofDF > 0);nafillis to take your last observed value0.95and carry it forward for the remaining three rows