joshuaulrich / xts

Extensible time series class that provides uniform handling of many R time series classes by extending zoo.
http://joshuaulrich.github.io/xts/
GNU General Public License v2.0
220 stars 71 forks source link

window function works in version 0.9-7 not working in version 0.11-2 #312

Closed annaymj closed 3 years ago

annaymj commented 4 years ago

The window function works in an older version (0.9-7), but fails the new version.

out.early.xts.window <- window(out.early.xts,start=1995.00)
Error in .toPOSIXct(start, indexTZ(x)) : invalid time / time based class

Can you share an example of work around ?

Was trying to install the old version using the following command, but runs into compilation issue

require(devtools)
install_version("xts", "0.9-7","http://cran.us.r-project.org")
ERROR: compilation failed for package 'xts'
ethanbsmith commented 4 years ago

what is 1995.00 is supposed to represent? maybe you want out.early.xts.window <- window(out.early.xts, start=.POSIXct(1995.00)) or out.early.xts.window <- window(out.early.xts, start=as.POSIXct("1995-01-01"))

annaymj commented 4 years ago

It's the year name. The workaround code seems working.

Thank you!

annaymj commented 4 years ago

Update. 1995.00 means year 1995 quarter Q1. 1996.25 (1996 Q2). Those works in the old library version.

.POSIXct(1995.00) is returning very weird result.

.POSIXct(1995.00) [1] "1970-01-01 00:33:15 UTC"

as.POSIXct("1995-01-01") is working

as.POSIXct("1995-01-01") [1] "1995-01-01 UTC" Do you have an easy method to convert 1995.00 to "1995-01-01"?

Also do you have plan to make 1995.00 format working for the updated version?

Thanks a lot!

joshuaulrich commented 4 years ago

Hi @annaymj. I'll investigate the prior behavior and make sure it is not broken in the new version.

joshuaulrich commented 4 years ago

Hi @annaymj, can you please provide an example of the out.early.xts and out.early.xts.window objects, when run under 0.9-7? The window.xts() method was added in 0.11-0, so window.zoo() would have been dispatched in any prior version of xts.

I can get your example to work if the index is yearmon or yearqtr, but not if it's Date.

R> x <- xts(1:12, seq(as.yearqtr(2007), by=1/4, length.out=12))
R> window(x, start=2009)
        [,1]
2009 Q1    9
2009 Q2   10
2009 Q3   11
2009 Q4   12
R> ix <- seq(as.yearmon(2007), by=1/12, length.out=36)
R> head(window(xts(1:36, ix), start=2009))
         [,1]
Jan 2009   25
Feb 2009   26
Mar 2009   27
Apr 2009   28
May 2009   29
Jun 2009   30
R> ix <- as.Date(ix)
R> head(window(xts(1:36, ix), start=2009))  # starts in 2007, not 2009
           [,1]
2007-01-01    1
2007-02-01    2
2007-03-01    3
2007-04-01    4
2007-05-01    5
2007-06-01    6
R> packageVersion("xts")
[1] '0.9.7'