I have been able to create an xts object in the past with basic tables consisting of floats and dates in the POSIX format. Yet I have no idea why the xts function is throwing an error on this type of data. Here is a sample of it
carries on with 0s until this kind of data
My code simply goes as follow
graph <- xts(sample$data, order.by = sample$date)
dygraph(graph)
And would throw the error I specified in the title of the topic. I am slightly confused as to why that is.
Edit: rescaling with dput for test purposes:
structure(list(data = list(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0), date = structure(c(1543434776.963,
1542820106.015, 1543615640.482, 1543851212.862, 1543854217.269,
1543930726.949, 1544030657.079, 1544034770.003, 1544043898.003,
1544457518.498, 1544460092.511, 1544467414.991, 1544470840.541,
1544628952.371, 1544473221.584, 1544631972.069, 1544646951.827,
1544645607.091, 1542833838.068, 1542819507.303), class = c("POSIXct",
"POSIXt"))), row.names = c(NA, 20L), class = "data.frame")
The column 'data' is list
(checked by str(sample)
), unlist
it to a vector
and it should work
library(xts)
xts(unlist(sample$data), order.by = sample$date)
# [,1]
#2018-11-21 11:58:27 0
#2018-11-21 12:08:26 0
#2018-11-21 15:57:18 0
#2018-11-28 14:52:56 0
#2018-11-30 17:07:20 0
#2018-12-03 10:33:32 0
#2018-12-03 11:23:37 0
#2018-12-04 08:38:46 0
#2018-12-05 12:24:17 0
#2018-12-05 13:32:50 0
#2018-12-05 16:04:58 0
#2018-12-10 10:58:38 0
#2018-12-10 11:41:32 0
#2018-12-10 13:43:34 0
#2018-12-10 14:40:40 0
#2018-12-10 15:20:21 0
#2018-12-12 10:35:52 0
#2018-12-12 11:26:12 0
#2018-12-12 15:13:27 0
#2018-12-12 15:35:51 0