title: R data extraction from panel data
body: <p>I have a long time series in a table from which I want to extract values.</p>
  
  <p>The panel has daily observations but some NA. I would like to extract the last non-NA value from each cross section, into a new time series. It should go to the same cross section, and fill all the observations within that cross section with the extracted value. I.e the new time series will consist of stacked cross sections with data in every t.</p>
  
  <p>I have made an example of the structure below, where x is the series from which I want to extract the data, and NEW the new series I want to create.</p>
  
  <pre><code>xsection  t       x       NEW
  01_00 2000-01-01 146,16 147,2
  01_00 2000-01-02 147,2  147,2
  01_00 2000-01-03 NA     147,2
  02_00 2000-01-01 NA     148,3
  02_00 2000-01-02 148,3  148,3
  02_00 2000-01-03 NA     148,3
  03_00 2000-01-01 145,9  147,4
  03_00 2000-01-02 NA     147,4
  03_00 2000-01-03 147,4  147,4
  </code></pre>
  
  <p>I have also created a pdata.frame where cross section and time id are specified in the same row.</p>
  
  <pre><code>row.names              x
  01_00-2000-01-01    146.16  
  01_00-2000-01-02    147,2   
  01_00-2000-01-03    NA  
  </code></pre>
  
  <p>I'm new to R so I appreciate your advice.</p>
  
  <p>*Edit
  Structure of table:</p>
  
  <pre><code>Classes ‘data.table’ and 'data.frame':  7212530 obs. of  6 variables:
   $ var01 : Factor w/ 1018 levels "01_00","01_01",..: 1 1 1 1 1 1 1 1 1 1 ...
   $ id01  : Factor w/ 7085 levels "1995-09-25","1995-09-26",..: 1 2 3 4 5 6 7 8 9 10 ...
   $ spot  : num  146 146 145 146 147 ...
   $ weekly: num  NA NA NA NA NA NA NA NA NA NA ...
   $ NEW   : num  241 241 241 241 241 ...
   $ NEW3  : num  241 241 241 241 241 ...
   - attr(*, ".internal.selfref")=&lt;externalptr&gt; 
  </code></pre>