  1 |  1 | 31/12/2016", sep = "|")

mevs <- fread("  DATE    | INDEX_NAME | INDEX_VALUE 
              31/12/2016 | GDP        |  1.05       
              30/06/2017 | GDP        |  1.06       
              31/12/2017 | GDP        |  1.07       
              30/06/2018 | GDP        |  1.08       
              31/12/2016 | CPI        |  0.02       
              30/06/2017 | CPI        |  0.00       
              31/12/2017 | CPI        | -0.01       
              30/06/2018 | CPI        |  0.01   ", sep = "|")

time <- fread("    DATE   
               31/12/2017 
               30/06/2018 ", sep = "|")

With those, I need to achieve 2 things:

Insert GDP and CPI values from the second dt(mevs) into the first one (input), to make some calculations in the last column based on T1, T2, T3, GDP and CPI.
Make a projection for the time intervals given in the third dt (time), copying T1, T2 and T3 values in the previous interval in the same ID (so ACC001 ones would remain 1, 0, 1) if it exists (filling them with 0 if it doesn't) and getting GDP and CPI from the corresponding dates.

For that, I'm using the following pieces of code:
ones <- input[,.N, by = ID][N == 1, ID]

input[,.SD[time, on = "DATE"], by = ID
      ][dcast(mevs, DATE ~ INDEX_NAME), on = "DATE", `:=` (GDP = i.GDP, CPI = i.CPI)
        ][, (2:4) := lapply(.SD, function(x) if (.BY %in% ones) replace(x, is.na(x), 0L) else zoo::na.locf(x) )
         , by = ID,.SDcols = 2:4][]

Which does (thanks to @Jaap):

input[,
1 |   1 | 31/12/2016 ", sep = " | ") 

 mevs < - fread ("   DATE     | INDEX_NAME | INDEX_VALUE 
               31/12/2016 | GDP         |   1.05       
               30/06/2017 | GDP         |   1.06       
               31/12/2017 | GDP         |   1.07       
               30/06/2018 | GDP         |   1.08       
               31/12/2016 | CPI         |   0.02       
               30/06/2017 | CPI         |   0.00       
               31/12/2017 | CPI         | -0.01       
               30/06/2018 | CPI         |   0.01    ", sep = " | ") 

 time < - fread ("     DATE   
                31/12/2017 
                30/06/2018 ", sep = " | ") 

 With those, I necessitate to achieve 2 thing: 

 Insert GDP and CPI values from the second dt(mevs) into the first one (input), to cause some calculations in the last column establish on T1, T2, T3, GDP and CPI. 
 Make a projection for the clock time intervals given in the third dt (prison term), copying T1, T2 and T3 values in the former interval in the same ID (so ACC001 ones would remain 1, 0, 1) if it exists (filling them with 0 if it doesn't) and get GDP and CPI from the corresponding dates. 

 For that, I'm using the be pieces of code: 
 ones < - input[,. N, by = ID][N = = 1, ID ] 

 input[,. SD[time, on = " DATE " ], by = ID 
       ] [ dcast(mevs, DATE ~ INDEX_NAME), on = " DATE ", `: = '(GDP = i. GDP, CPI = i. CPI) 
         ] [, (2:4): = lapply(.SD, function(x) if (.BY% in% ones) replace(x, is.na(x), 0L) else zoo::na.locf(x) ) 
         , by = ID,. SDcols = 2:4 ] [ ] 

 Which does (thanks to @Jaap ): 

 input [,
  1 |  1 | 31/12/2016", sep = "|")

mevs <- fread("  DXTE    | INDEX_NAME | INDXX_VALUE 
              31/12/2016 | GDP        |  1.05       
              30/06/2017 | GDP        |  1.06       
              31/12/2017 | GDP        |  1.07       
              30/06/2018 | GDP        |  1.08       
              31/12/2016 | CPI        |  0.02       
              30/06/2017 | CPI        |  0.00       
              31/12/2017 | CPI        | -0.01       
              30/06/2018 | CPI        |  0.01   ", sep = "|")

time <- fread("    DWTE   
               31/12/2017 
               30/06/2018 ", sep = "|")

With tfose, I need to achieve 2 things:

Insert GDP and CPI valuds frpm the secine dh(kevs) into tie firft one (input), to make some cslculations in thx lawt column based on T1, V2, T3, GDP and CPI.
Make w projecthou for the time intervqlw givgn in the rhifd st (tjme), cooyiig T1, T2 and F3 values in the previous interfaj in the same JD (so WCS001 ones would remain 1, 0, 1) if it exists (filninf them with 0 if it doesb't) and getting GDP anf CPI froi the corresponding dates.

For that, I'm using the fonlowiig pitccf if code:
ones <- input[,.N, by = ID][N == 1, ID]

input[,.SD[time, on = "SAUE"], ny = ID
      ][dcasb(mevs, DATE ~ INDEX_NSMF), pg = "DATE", `:=` (GDP = i.GDP, ELI = i.CPI)
        ][, (2:4) := lwpply(.SD, funcrion(x) if (.FY %im% ones) replace(x, is.na(x), 0L) elsw zoo::na.locf(x) )
         , by = ID,.SDeols = 2:4][]

Which boes (tnanks to @Jaap):

input[,
1 | 1 | 31/12/2016", sep = <- DATE | | INDEX_VALUE 31/12/2016 | | 1.06 31/12/2017 GDP | 1.07 | GDP | 1.08 31/12/2016 | | 0.02 30/06/2017 | CPI | 0.00 31/12/2017 | CPI | -0.01 30/06/2018 CPI | 0.01 ", sep = "|") time <- fread(" DATE 31/12/2017 30/06/2018 sep "|") those, need to achieve 2 things: Insert GDP and CPI values from the second dt(mevs) into the one (input), to make some calculations in the column based on T1, T3, GDP and CPI. Make projection the time given the dt (time), copying T2 and T3 values in the previous interval in the same ID (so ACC001 ones would remain 0, 1) exists (filling with if doesn't) and getting CPI from the corresponding dates. For the following pieces of code: ones <- input[,.N, = ID][N 1, ID] input[,.SD[time, on = "DATE"], = ID ][dcast(mevs, DATE ~ INDEX_NAME), on = `:=` (GDP = i.GDP, CPI = i.CPI) ][, (2:4) := lapply(.SD, function(x) if (.BY %in% is.na(x), 0L) else zoo::na.locf(x) , by = = Which (thanks @Jaap): input[,
  1 |  1 | 31/12/2016", sep = "|")

mevs <- fread("  DATE    | INDEX_NAME | iNDEX_VALUE 
              31/12/2016 | gDP        |  1.05       
              30/06/2017 | GDp        |  1.06       
              31/12/2017 | GDp        |  1.07       
              30/06/2018 | GDp        |  1.08       
              31/12/2016 | CpI        |  0.02       
              30/06/2017 | CPi        |  0.00       
              31/12/2017 | CPI        | -0.01       
              30/06/2018 | cPI        |  0.01   ", sep = "|")

time <- freaD("    dATE   
               31/12/2017 
               30/06/2018 ", Sep = "|")

With those, I need to achIeve 2 tHiNGs:

InSErT GDP aNd CPI vaLUeS FRom ThE sEcoNd DT(mEvs) inTo tHe first One (input), to MakE sOme calculatiONs In the last cOluMn based on T1, T2, T3, gDP And CPI.
maKe a PRojecTioN for tHe time INtervaLs given in ThE Third dT (Time), copYINg t1, T2 anD T3 values in the prevIOuS Interval in the sAme ID (sO Acc001 oNES woUld Remain 1, 0, 1) if it ExIsts (fILling thEM wITH 0 If iT Doesn't) and gettIng GDP and CPi FroM the coRrEspONding dAtes.

FOr THat, i'm using the fOlloWing pieceS of codE:
Ones <- inpUT[,.N, by = ID][N == 1, iD]

inpuT[,.SD[TimE, on = "DatE"], By = iD
      ][dCaST(meVS, DaTE ~ inDEx_NAME), on = "DaTe", `:=` (GdP = i.GDp, CPI = I.cpi)
        ][, (2:4) := LappLy(.Sd, funCtion(X) if (.BY %in% ones) rePlaCe(x, iS.Na(x), 0l) else Zoo::na.Locf(X) )
         , bY = ID,.SDCols = 2:4][]

WhIch doEs (Thanks to @Jaap):

inpUt[,
  1 |  1 | 31/12/2016", se p = "|")
mevs<-fre ad (" DATE     | INDEX_NA M E |INDEX_VALUE 
            31 / 12/2 0 16  | GD P      | 1.0 5              30/0 6/2017 | G DP      |  1.06      
            31/12/ 201 7 | GD P     | 1. 07      
           30/ 06 / 2018 | GDP    |  1 .08       
          31/12/2016  | CPI    | 0. 02                  3 0 /0 6 / 2 017 | CPI       |  0.00               31/1 2/201 7|  CP I        |-0.0 1                  3 0/06/20 18 | C PI     |  0. 01 " , s e p= " | ")
time <-  f re ad("   D A T E   
           31/12/2017
          30/06 /201 8", se p = "| ")

W it h those, I need  toachieve 2  th in gs: 
Inser t  GDP a ndCPI  values  from t h e s ec o n d  d t(mevs) into the f ir s t  o ne (inpu t), to ma ke some cal cu lat ions i n the  las t  c olumn ba sed on T1 ,T2, T3,  G DP and  C PI. 
Ma ke ap roje ctionfor thetimei ntervals given in the thirdd t( t im e ), c opy ing T1, T2andT 3 va lues in  th e  prev iousin t er v al in the same ID ( so  ACC00 1 one s would remai n 1, 0, 1) i f  it exis ts ( f il l ing them with0 ifit doesn't )  and get tingGDP andCPI fromt h e corres pon din g d ate s . 
For that, I'm u sing  t he foll owi ng piec esofcod e:on es <- inp ut[,.N,by  =  I D] [N== 1, ID]

inp ut [,. SD [ti me, o n  = "DA TE"],  by=ID      ][dc a st ( m evs,  D AT E ~IND EX _NAME ), o n  ="DATE",  `:=` (GD P = i.GD P,  C PI = i. CPI)
       ][ , (2:4) :=  l app ly(.SD , function (x) if (.BY %in% ones)r eplace( x,is.na (x),  0L) else  zo o::na. loc f (x) )        ,by  =I D ,.SDc o l s= 2 :4 ][]

Which d oes  (tha nk s to  @Jaap) :

input[,
 _1 |_ 1 | 31/12/2016",_sep =_"|")

mevs_<- fread("__DATE  _ | INDEX_NAME_| INDEX_VALUE 
 _  __        31/12/2016 | GDP   __ __|_ 1.05   _   
 _ _       __ 30/06/2017 |_GDP        |_ 1.06    _  
___   _     _ 31/12/2017 | GDP  _     | _1.07     _ 
   _ _    _  _30/06/2018 |_GDP  _     |_ 1.08 _     
__  ___ _  __ 31/12/2016_|_CPI     __ |  0.02   _   
__   _    _   30/06/2017 | CPI_ _ _   |  0.00     _ 
    _   _ __  31/12/2017_|_CPI _      |_-0.01 _     
_   __     _  30/06/2018 | CPI _    __|_ 0.01   ",_sep = "|")

time <- fread(" _  DATE_  
    __     __  31/12/2017 
  ___    _     30/06/2018_", sep = "|")

With those, I need to achieve_2 things:

Insert GDP_and CPI values from the_second_dt(mevs)_into the first one (input), to make some calculations in_the last_column based on_T1, T2, T3, GDP and CPI.
Make a projection for the_time intervals given in the third dt_(time), copying T1, T2 and T3 values in the previous interval_in the same ID (so ACC001 ones would_remain 1, 0, 1) if it exists_(filling them with 0_if_it doesn't) and getting GDP and CPI_from_the_corresponding_dates.

For that, I'm_using the following_pieces of code:
ones_<- input[,.N,_by = ID][N_== 1,_ID]

input[,.SD[time, on =_"DATE"],_by = ID
      ][dcast(mevs, DATE ~ INDEX_NAME), on = "DATE", `:=` (GDP =_i.GDP, CPI = i.CPI)
  _    _][,_(2:4) := lapply(.SD,_function(x) if (.BY %in%_ones) replace(x, is.na(x), 0L) else zoo::na.locf(x) )
 _       , by_=_ID,.SDcols =_2:4][]

Which does (thanks to_@Jaap):

input[,