I am using R 3.2.1 for Mac OS X and seem to have run into incorrect behavior in xts subsetting. In brief, subsetting monthly data give a result that is 1 month lagged from what it should be. Here is a simple example that is similar to an analysis of paleotemperature I am doing:
First I will make some test data for the example:
xts.test <- xts(rnorm(440*12, mean=0, sd=10),order.by=timeBasedSeq(155001/1989))
This produces a correct xts
file AFAICT. Here is the first year of 12 months.
head(xts.test, 12L)
[,1]
Jan 1550 -6.9301845
Feb 1550 12.1581413
Mar 1550 3.9688139
Apr 1550 3.9540268
May 1550 9.8200923
Jun 1550 -4.2090998
Jul 1550 7.5950340
Aug 1550 -6.5967389
Sep 1550 -0.6736532
Oct 1550 6.4939221
Nov 1550 4.3916465
Dec 1550 19.8800872
However, when I try to subset this by selecting for a single year, I get the following:
xts.test["1550"]
[,1]
Feb 1550 12.1581413
Mar 1550 3.9688139
Apr 1550 3.9540268
May 1550 9.8200923
Jun 1550 -4.2090998
Jul 1550 7.5950340
Aug 1550 -6.5967389
Sep 1550 -0.6736532
Oct 1550 6.4939221
Nov 1550 4.3916465
Dec 1550 19.8800872
Jan 1551 -2.9549224
That is, instead of the correct Jan-Dec 1550, I get Feb 1550 through Jan 1551
I get a similar lag when I try to subset by selecting months of a year. c(2, 3,4,5,6,7)
get me April through September instead of March through August.
Any thoughts here?