【问题标题】:Time series with 1 minute frequency in R using the ts() function使用 ts() 函数在 R 中具有 1 分钟频率的时间序列
【发布时间】:2020-08-27 12:21:41
【问题描述】:

我有 18,596 个温度数据,间隔 1 分钟,从 2017-05-31T17:02:30.000Z 到 2017-06-13T14:57:30.000Z。我想使用 ts() 函数创建一个频率为每 1 分钟的时间序列对象。我尝试了以下方法,但显然不起作用:

ts(data, start=c(2017,5,31,17,2,30), end=c(2017,6,13,14,57,30))

我应该怎么写?

非常感谢!

【问题讨论】:

    标签: r time-series


    【解决方案1】:

    下面的呢:

    # find out how many minutes are in this period
    (as.numeric(as.POSIXct("2017-06-13 14:57:30")) -
      as.numeric(as.POSIXct("2017-05-31 17:02:30"))) / 60
    # 18595
    
    # create a time series object (random data as example)
    tsdat <- ts(data = rnorm(18595), 
      start = as.numeric(as.POSIXct("2017-05-31 17:02:30")),
      end = as.numeric(as.POSIXct("2017-06-13 14:57:30")), 
      frequency = 60)
    

    或者,更好的是,使用 zooxts 包中的扩展时间序列对象:

    library("zoo")
    tsdat <- zoo(rnorm(18596), 
      order.by = seq(as.POSIXct("2017-05-31 17:02:30"), length=18596, by="min"))
    head(tsdat)
    
    
    library("xts")
    tsdat <- xts(rnorm(18596), 
      order.by = seq(as.POSIXct("2017-05-31 17:02:30"), length=18596, by="min"))
    head(tsdat)
    

    更多相关信息请见here

    【讨论】:

      猜你喜欢
      • 2013-11-13
      • 2013-07-18
      • 2018-08-05
      • 2019-09-06
      • 2012-07-23
      • 1970-01-01
      • 2013-02-12
      • 2018-06-24
      • 2014-02-16
      相关资源
      最近更新 更多