我想将年份值和季度值转换为时间序列数据。
quaterly_data <- c(30.53,36.36,40.73,45.19,
55.67,63.19,72.2,81.19,
100.37,120.32,141.64,143.89,
154.14,164.5,174.32,189.26,
224.13,239.35,255.95,277.23)
#quarterly dates
library(zoo)
quarterly_dates <- as.yearqtr(seq(as.Date("2002/3/1"), as.Date("2006/12/1"), by = "3 months"))
日期如下所示:
[1] "2002 Q1" "2002 Q2" "2002 Q3" "2002 Q4" "2003 Q1" "2003 Q2" "2003 Q3" "2003 Q4" "2004 Q1" "2004 Q2"
[11] "2004 Q3" "2004 Q4" "2005 Q1" "2005 Q2" "2005 Q3" "2005 Q4" "2006 Q1" "2006 Q2" "2006 Q3" "2006 Q4"
我想编写一个函数来删除第一个元素“2002 Q1”,并将其放入myts <- ts( Quarterly_data,start = c(2002, 1), frequency = 4)。但我不知道该怎么做。