interpolate data and merge.zoo error


#1

I try to interpolate irregular space time series into regular space, for analyzing meter value (export Wh of gas meter), by referring from this link: https://stackoverflow.com/questions/38723185/how-to-turn-interpolate-this-irregularly-spaced-time-series-into-a-regularly-s)

There are 75991 obs. of 3 variables, in my dataset.

localminute,dataid,meter_value
2015-10-01 00:03:02-05,2034,72376
2015-10-01 00:04:18-05,2034,72376
2015-10-01 00:05:18-05,2034,72376
2015-10-01 00:09:47-05,2034,72376
2015-10-01 00:12:48-05,2034,72376
2015-10-01 00:17:32-05,2034,72376

Full data file can be downloaded from this link: https://drive.google.com/open?id=1h-JYvXWlIqiJnaMWvU-RRhRVcQdYKexI

Since, time series in my dataset, is not regular, thus I could not do any forecasting. I try to convert to regular and use read.zoo function, but I get error in merging dummy data and read.zoo data. Thus I could not proceed for plotting the existing data and interpolating data. My R code as below:

ReadData2034 <- data.table::fread("test_2034.csv",blank.lines.skip = TRUE)

ReadData2034 <- ReadData2034 %>% mutate(localminute=lubridate::as_datetime(localminute))
    
D2034p <- paste0(ReadData2034$localminute,",",ReadData2034$meter_value,"\n",collapse="")
    
str(D2034p)
  # chr "2015-10-01 05:03:02,72376\n2015-10-01 05:04:18,72376\n2015-10-01 05:05:18,72376\n2015-10-01 05:09:47,72376\n201"| __truncated__


I got warning message in read.zoo function and got error in merging read.zoo data (D2034z) and dummy data.

D2034z <- read.zoo(text=D2034p, sep = ",", header = TRUE, index = 1:1, tz = "", format = "%Y-%m-%d %H:%M:%S")
# Warning message:
#   In zoo(rval3, ix) :
#   some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique

t <- time(D2034z) #output of 't' as below
# [1] "2014-04-21 +08" "2014-09-21 +08" "2014-10-16 +08" "2014-11-18 +08"
# [5] "2014-12-08 +08" "2015-01-22 +08" "2015-02-26 +08" "2015-03-20 +08"
# [9] "2015-04-09 +08" "2015-04-29 +08" "2015-09-16 +08" "2015-10-13 +08"
# [13] "2015-11-10 +08" "2015-12-16 +08" "2016-01-27 +08" "2016-02-23 +08"
# [17] "2016-03-22 +08" "2016-04-04 +08" "2016-04-11 +08"

diff(t)
 # Time differences in secs
# [1]   60  269  181  284  120  750  405   76   29   45  165   91  104  286  329
# [16]  255   61  434  556   14  301  209   45   60  285   90   61  134  166  224
# [991]   60  135   90   75  180  210  270  554  436  210
              # [ reached getOption("max.print") -- omitted 74989 entries ]

t.biweekly <- seq(from = min(t), to=max(t),by="5000000 secs")
# [1] "2014-04-21 00:00:00 +08" "2014-06-17 20:53:20 +08"
# [3] "2014-08-14 17:46:40 +08" "2014-10-11 14:40:00 +08"
# [5] "2014-12-08 11:33:20 +08" "2015-02-04 08:26:40 +08"
# [7] "2015-04-03 05:20:00 +08" "2015-05-31 02:13:20 +08"
# [9] "2015-07-27 23:06:40 +08" "2015-09-23 20:00:00 +08"
# [11] "2015-11-20 16:53:20 +08" "2016-01-17 13:46:40 +08"
# [13] "2016-03-15 10:40:00 +08"

dummy <- zoo( ,t.biweekly)
# Data:
#   numeric(0)
# 
# Index:
# [1] "2014-04-21 00:00:00 +08" "2014-06-17 20:53:20 +08"
# [3] "2014-08-14 17:46:40 +08" "2014-10-11 14:40:00 +08"
# [5] "2014-12-08 11:33:20 +08" "2015-02-04 08:26:40 +08"
# [7] "2015-04-03 05:20:00 +08" "2015-05-31 02:13:20 +08"
# [9] "2015-07-27 23:06:40 +08" "2015-09-23 20:00:00 +08"
# [11] "2015-11-20 16:53:20 +08" "2016-01-17 13:46:40 +08"
# [13] "2016-03-15 10:40:00 +08"

z.interpolated <- merge(D2034z,dummy,all=TRUE)
# Error in merge.zoo(D2034z, dummy, all = TRUE) : 
#   series cannot be merged with non-unique index entries in a series

May I know how to resolve that error in merge.zoo?