【发布时间】:2018-02-07 14:45:23
【问题描述】:
我正在尝试将存储在data.table 中的季度数据转换为面板 data.frame 以准备进一步分析。但显然在使用季度日期作为时间维度时存在问题。
我可以将它们转换为日期、数字或字符,但 is.pconsecutive() 不会将其识别为季度时间序列,这会阻止我使用某些功能。
library(zoo)
library(data.table)
dt <- structure(list(Global.Company.Key = c(1380L, 1380L, 1380L, 1380L,
1380L, 1380L, 1380L, 1380L), Calendar.Data.Year.and.Quarter = structure(c(2000,
2000.25, 2000.5, 2000.75, 2001, 2001.25, 2001.5, 2001.75), class = "yearqtr"),
Calendar.Year.Quarter.Integer = c(10957L, 11048L, 11139L,
11231L, 11323L, 11413L, 11504L, 11596L), Year.Date = structure(c(10957,
11048, 11139, 11231, 11323, 11413, 11504, 11596), class = "Date")), .Names = c("Global.Company.Key",
"Calendar.Data.Year.and.Quarter", "Calendar.Year.Quarter.Integer",
"Year.Date"), row.names = c(NA, -8L), class = c("data.table",
"data.frame"))
# defined the date index as integer
pdt <- pdata.frame(dt, index = c("Global.Company.Key", "Calendar.Year.Quarter.Integer"))
is.pconsecutive(pdt)
1380
FALSE
显然,时间维度是通过检查数据点之间的距离是否规则间隔为 1 来分析的。来自手册:“为了评估连续性,时间维度被解释为数字,并且数据被测试为一个规则间隔的序列,每个人的时间段之间的距离为 1(对于每个人,时间维度可以解释为作为序列 t, t+1, t+2, ... 其中 t 是一个整数)。” 那么转换年季度时间序列的最佳和最稳健的方法是什么?
【问题讨论】: