Reputation: 328
I'm trying to write a simple code to understand the zoo package, but I'm always having issues with the window function. Everytime I call it, no matter if it is with my data or randomly generated data, I get the value as "without observations".
Here's the code I'm trying to use:
upper.bound <- as.Date(paste("01", "06", "2013", sep="-"), format="%d-%m-%Y")
lower.bound <- as.Date(paste("30", "09", "2013", sep="-"), format="%d-%m-%Y")
all_dates <- seq(as.Date(upper.bound), as.Date(lower.bound), by="day")
Z <-zoo(rnorm(200), order.by=all_dates)
x <- window(Z, upper.bound, lower.bound)
Upvotes: 0
Views: 34
Reputation: 263301
The second argument to window.zoo is index
so what you thought was being matched to the start
-date was not. Instead, remember to name your arguments:
?window.zoo
x <- window(Z, start=upper.bound, end=lower.bound)
x
#------------
2013-06-01 2013-06-02 2013-06-03 2013-06-04 2013-06-05 2013-06-06 2013-06-07
-0.356725268 0.165033118 -0.871486715 0.614054310 2.177144652 1.099383297 0.332047374
2013-06-08 2013-06-09 2013-06-10 2013-06-11 2013-06-12 2013-06-13 2013-06-14
-1.203846835 1.996777866 -0.035678205 -0.999349827 -0.216802437 -0.620288147 -1.427030534
2013-06-15 2013-06-16 2013-06-17 2013-06-18 2013-06-19 2013-06-20 2013-06-21
-0.300081002 -0.666034846 -0.662918833 0.737737776 -0.206665685 -1.183924183 -0.119519035
2013-06-22 2013-06-23 2013-06-24 2013-06-25 2013-06-26 2013-06-27 2013-06-28
-0.012132861 -0.155492086 0.630016249 0.454951717 1.240600750 0.212195020 1.529695315
2013-06-29 2013-06-30 2013-07-01 2013-07-02 2013-07-03 2013-07-04 2013-07-05
-0.791875017 -0.002926672 0.333920298 0.272069968 -0.152630683 0.324500744 -0.004795280
2013-07-06 2013-07-07 2013-07-08 2013-07-09 2013-07-10 2013-07-11 2013-07-12
0.879553367 -0.212456832 1.990937136 -0.389366651 0.763931167 1.860765480 0.015482952
2013-07-13 2013-07-14 2013-07-15 2013-07-16 2013-07-17 2013-07-18 2013-07-19
snipped output
Upvotes: 1