title: R time series missing values
body: <p>I was working with a time series dataset having hourly data. The data contained a few missing values so I tried to create a dataframe (time_seq) with the correct time value and do a merge with the original data so the missing values become 'NA'. </p>
  
  <pre><code>&gt; data
  
       date                 value
  7980 2015-03-30 20:00:00  78389
  7981 2015-03-30 21:00:00  72622
  7982 2015-03-30 22:00:00  65240
  7983 2015-03-30 23:00:00  47795
  7984 2015-03-31 08:00:00  37455
  7985 2015-03-31 09:00:00  70695 
  7986 2015-03-31 10:00:00  68444
  
  //converting the date in the data to POSIXct format.
  
  &gt; data$date &lt;- format.POSIXct(data$date,'%Y-%m-%d %H:%M:%S') 
  
  // creating a dataframe with the correct sequence of dates. 
  
  &gt; time_seq &lt;- seq(from = as.POSIXct("2014-05-01 00:00:00"), 
                to = as.POSIXct("2015-04-30 23:00:00"), by = "hour")
  
  &gt; df &lt;- data.frame(date=time_seq)
  
  &gt; df 
  
       date            
  8013 2015-03-30 20:00:00
  8014 2015-03-30 21:00:00
  8015 2015-03-30 22:00:00
  8016 2015-03-30 23:00:00
  8017 2015-03-31 00:00:00
  8018 2015-03-31 01:00:00
  8019 2015-03-31 02:00:00
  8020 2015-03-31 03:00:00
  8021 2015-03-31 04:00:00
  8022 2015-03-31 05:00:00
  8023 2015-03-31 06:00:00
  8024 2015-03-31 07:00:00
  
  // merging with the original data
  
  &gt; a &lt;- merge(data,df, x.by = data$date, y.by = df$date ,all=TRUE)
  
  &gt; a    
         date                 value
   4005  2014-07-23 07:00:00   37003
   4006  2014-07-23 07:30:00       NA
   4007  2014-07-23 08:00:00   37216
   4008  2014-07-23 08:30:00       NA
  </code></pre>
  
  <p>The values I get after merging are incorrect and they contain half-hourly values. What would be the correct approach for solving this? </p>
  
  <p>Why are is the merge result in 30 minute intervals when both my dataframes are hourly?</p>
  
  <p>PS:I looked into this question : <a href="https://stackoverflow.com/questions/22956803/fastest-way-for-filling-in-missing-dates-for-data-table">Fastest way for filling-in missing dates for data.table</a> and followed the steps but it didn't help.</p>