2016-04-14 58 views
0

我想寫一個簡單的代碼來理解動物園包,但我總是有窗口函數的問題。每次我打電話時,無論是使用我的數據還是隨機生成的數據,我都會得到「無觀察值」的值。窗口總是返回沒有意見

這裏是我想要使用的代碼:

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) 

回答

1

的第二個參數是window.zoo所以index你以爲發生了什麼被匹配到start -date沒有。相反,請記住命名您的論點:

?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