“ xdata对象创建时,xdata(x):当前不支持的数据类型”

问题描述 投票:-1回答:1

我过去能够使用POSIX格式的浮点数和日期组成的基本表创建一个xts对象。但是我不知道为什么xts函数会在此类数据上引发错误。这是一个样本enter image description here

继续进行0直到此类数据enter image description here

我的代码简单如下

graph <- xts(sample$data, order.by = sample$date)
dygraph(graph)

并且会抛出我在主题标题中指定的错误。我对此有些困惑。

编辑:使用dput重新缩放以进行测试:

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")
r xts dygraphs
1个回答
0
投票

[数据列]是list(由str(sample)选中),unlistvector,它应该可以工作

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
© www.soinside.com 2019 - 2024. All rights reserved.