我使用to.monthly
包中的xts
命令将不均匀间隔的时间序列转换为月度时间序列,但答案中省略了几个月。
例如,我的数据集如下:DXts
[,1]
2001-03-22 57.0
2001-05-09 42.0
2001-08-15 56.0
2001-09-17 58.0
2002-03-11 66.0
2002-05-29 53.0
2002-07-17 53.0
2002-09-11 48.0
2003-03-21 63.0
2003-03-23 64.0
2003-05-22 42.0
2003-07-22 45.0
2003-09-09 51.0
2004-03-15 57.0
2004-05-16 44.0
2004-07-28 58.0
2004-09-20 59.0
2005-03-18 64.0
2005-05-27 38.0
2005-07-21 52.0
2005-09-15 54.0
2006-09-09 54.0
2007-09-06 62.0
2008-09-05 62.0
2009-09-14 49.3
2010-09-14 60.2
2011-09-13 64.6
2012-09-12 70.2
2013-05-09 39.7
2013-06-06 51.3
2013-07-11 52.3
2013-08-09 53.1
2013-09-05 52.7
2013-10-17 56.6
2013-11-06 57.1
2013-12-04 55.3
2014-01-10 60.3
2014-02-07 66.1
2014-03-11 62.7
2014-04-07 63.1
2014-05-09 38.4
2014-06-05 46.4
2014-07-10 54.0
2014-08-12 57.3
2014-09-06 62.1
2014-10-07 62.1
2014-12-04 76.4
2015-01-10 66.0
2015-02-11 67.9
2015-03-02 70.1
DXts<- xts(udata2[,-1], order.by=as.Date(udata2[,1], Dformat))
和to.monthly(DXts)[,1]:
DXts.Open
Mar 2001 57.0
May 2001 42.0
Aug 2001 56.0
Sep 2001 58.0
Mar 2002 66.0
May 2002 53.0
Jul 2002 53.0
Sep 2002 48.0
Mar 2003 63.0
May 2003 42.0
Jul 2003 45.0
Sep 2003 51.0
Mar 2004 57.0
May 2004 44.0
Jul 2004 58.0
Sep 2004 59.0
Mar 2005 64.0
May 2005 38.0
Jul 2005 52.0
Sep 2012 54.0
May 2013 39.7
Jun 2013 51.3
Jul 2013 52.3
Aug 2013 53.1
Sep 2013 52.7
Oct 2013 56.6
Nov 2013 57.1
Dec 2013 55.3
Jan 2014 60.3
Feb 2014 66.1
Mar 2014 62.7
Apr 2014 63.1
May 2014 38.4
Jun 2014 46.4
Jul 2014 54.0
Aug 2014 57.3
Sep 2014 62.1
Oct 2014 62.1
Dec 2014 76.4
Jan 2015 66.0
Feb 2015 67.9
Mar 2015 70.1
和2006-2009数据丢失。
提前感谢您的帮助。