【问题标题】:Creating time series in R with given time-stamps and values使用给定的时间戳和值在 R 中创建时间序列
【发布时间】:2016-08-02 08:58:43
【问题描述】:

我创建了以下时间序列

t = seq(as.POSIXct('2014-12-05 10:01:00'), length.out = 4, by = 'mins')
x = c(1,3,4,2)
y = as.ts(x,t)

当我尝试查看(在图中)我的时间序列时,时间标签不是我在 t 中输入的值。

plot(y)
time(y)
[1] 1 2 3 4

我该如何解决?

【问题讨论】:

  • 一种方法是改用xts 类:library(xts); y <- xts(x,t)

标签: r time-series


【解决方案1】:

我会使用xts 包,即。将时间序列创建为 xts 对象,然后利用 plot.xts

library(xts)
y.xts <- xts(x, t)
plot(y.xts)  

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-11
    • 1970-01-01
    • 1970-01-01
    • 2020-10-14
    • 2019-02-05
    • 1970-01-01
    相关资源
    最近更新 更多