title: insert new series rows based on time-stamp in R
body: <p>I have a data.table with two parameters(date and statues), now I want to insert new rows for the whole day based on the original table.</p>
  
  <p>data rules:</p>
  
  <ol>
  <li>the Status column contains only "0" and "1"</li>
  <li>the time-stamp which hasnt been recorded in the table is same with its next nearest tiemstamp in the table. </li>
  <li>the Date column is  always increase by time :)</li>
  </ol>
  
  <p>For example, a simple input:</p>
  
  <p><a href="https://i.stack.imgur.com/RGFd5.png" rel="nofollow"><img src="https://i.stack.imgur.com/RGFd5.png" alt="enter image description here"></a></p>
  
  <p>create the data with the code below:</p>
  
  <pre><code>   dd &lt;- data.table(date = c("2015-07-01 00:00:02", "2015-07-01 00:00:04", "2015-07-01 00:00:08"),
               status = c(0,1,0))
  </code></pre>
  
  <p>the out put is :</p>
  
  <p><a href="https://i.stack.imgur.com/sl8Vd.png" rel="nofollow"><img src="https://i.stack.imgur.com/sl8Vd.png" alt="enter image description here"></a></p>
  
  <p>my solution:</p>
  
  <ol>
  <li>calculate the time difference for each two rows, then save in a new column called time_diff</li>
  <li>insert new row in the loop based on the time_diff</li>
  </ol>
  
  <p>it could work, but the problem is the calculation time is too long, since so many loops. I thinks there could be an easier solution for this case </p>
  
  <p>Any help or suggestion would be greatly appreciated:)</p>
  
  <p>thanks!</p>