zooreg and window
Hi Achim, Yes, this worked. I added the two strings regts.start <- as.Date(regts.start) regts.end <- as.Date(regts.end) and changed the frequency to 1 in my zooreg call. The window call now works perfectly. I'm still wrapping my head around POSIXct and ISOdatetime and how they need to be applied appropriately! Thank you, Katrina On Thu, Apr 14, 2011 at 12:26 AM, Achim Zeileis
<Achim.Zeileis at uibk.ac.at> wrote:
On Wed, 13 Apr 2011, Katrina Bennett wrote:
Hello, I have a following time series data head(mend.dat) ID PARAM Year Month Day Value SYM 1 15052500 ? ? 1 1965 ? ? 5 ?15 ? 128 ? A 2 15052500 ? ? 1 1965 ? ? 5 ?16 ? 135 ? A 3 15052500 ? ? 1 1965 ? ? 5 ?17 ? 157 ? A 4 15052500 ? ? 1 1965 ? ? 5 ?18 ? 176 ? A 5 15052500 ? ? 1 1965 ? ? 5 ?19 ? 198 ? A 6 15052500 ? ? 1 1965 ? ? 5 ?20 ? 241 ? A I have loaded these data into as a zooreg object. The entire time series runs from 1965-05-15 until 2010-12-31. I have generated dates using ISOdatetime. regts.start <- ISOdatetime(year.start, mo.start, day.start, hour=0, min=0, sec=0, tz="GMT") regts.end <- ISOdatetime(year.end, mo.end, day.end, hour=0, min=0, sec=0, tz="GMT")
Here, you use "POSIXct" for your time index, below in the window() call you
use "Date". The latter is more appropriate here because you appear to have
daily data (and not intraday data).
Thus, you can do
regts.start <- as.Date(regts.start)
or create it from scratch via
regts.start <- as.Date("1965-05-15")
and analogously for regts.end.
The deltat in the zooreg() call is then simply 1.
Then, I generate a zoo time series from the data.
zts <- zooreg(mend.dat$Value, start = regts.start, end = regts.end,
frequency = 1, deltat = 86400)
I now want to subset using window.
window(zts, start=as.Date("2000-01-01"), end=as.Date("2000-01-02"))
This results in the following error message.
Data:
factor(0)
1496 Levels: ?100 1000 10000 101 1010 10100 102 1020 103 1030 104 1040
105 1050 10500 106 1060 107 1070 108 1080 ... Eqp
Index:
character(0)
Warning messages:
1: In which(in.index & all.indexes >= start & all.indexes <= end) :
?Incompatible methods ("Ops.POSIXt", "Ops.Date") for ">="
2: In which(in.index & all.indexes >= start & all.indexes <= end) :
?Incompatible methods ("Ops.POSIXt", "Ops.Date") for "<="
Why is this happening?
Thanks for your help.
Katrina Bennett
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Katrina E. Bennett PhD Student University of Alaska Fairbanks International Arctic Research Center 930 Koyukuk Drive, PO Box 757340 Fairbanks, Alaska 99775-7340 907-474-1939 office 907-385-7657 cell kebennett at alaska.edu Personal Address: UAF, PO Box 752525 Fairbanks, Alaska 99775-2525 bennett.katrina at gmail.com