【问题标题】:Extract part of time serie with R用 R 提取部分时间序列
【发布时间】:2013-12-18 06:18:17
【问题描述】:

我在 R 中有一个 ts(时间序列)对象,其中包含长时间的缺失值。我想提取其中的一部分并保留时间序列对象。

例如使用 AirPassengers 数据:

class(AirPassengers) 
#output: "ts"

但是如果我只提取第一个月的 10 个

AirPassengers[1:10]
#output: [1] 112 118 132 129 121 135 148 148 136 119

class(AirPassengers[1:10])
#output: "numeric"

如何在不丢失 ts 类的情况下简单地提取我的时间序列的一部分?

【问题讨论】:

标签: r time-series


【解决方案1】:

正如here所说,解决方案是使用window函数:

window(AirPassergers, 1960, c(1960, 4))

     Jan Feb Mar Apr
1960 417 391 419 461

【讨论】:

    猜你喜欢
    • 2013-09-08
    • 2017-06-25
    • 2014-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    相关资源
    最近更新 更多