我试图编写一个简单的代码来理解动物园包,但我总是遇到窗口函数的问题。每当我打电话给它时,无论是我的数据还是随机生成的数据,我得到的值都是"没有观察"。
这是我尝试使用的代码:
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)
答案 0 :(得分:1)
window.zoo的第二个参数是index
,所以你认为与start
- 日期相匹配的不是。相反,记得给你的论点命名:
?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