「単純な」固定ローリング ウィンドウを構築することは可能ですか? 次のデータセットがあるとします。
Apple Microsoft Tesla Amazon
2010 0.8533719 0.8078440 0.2620114 0.1869552
2011 0.7462573 0.5127501 0.5452448 0.1369686
2012 0.7580671 0.5062639 0.7847919 0.8362821
2013 0.3154078 0.6960258 0.7303597 0.6057027
2014 0.4741735 0.3906580 0.4515726 0.1396147
2015 0.4230036 0.4728911 0.1262413 0.7495193
2016 0.2396552 0.5001825 0.6732861 0.8535837
2017 0.2007575 0.8875209 0.5086837 0.2211072
#I want to be able to produce the following result
s.matrix <- x[1:4,]
#For the next period, I want to drop the first period and add the next period:
s.matrix <- x[2:5,]
#For the rest of the dataset it should be:
x[3:6,], x[4:7,], x[5:8,]
#That is, the width should always be equal to four.
私はlapplyが似たようなことをできることを知っていますが、最初の観測を削除せずに既存の行列に新しい変数を追加するだけのように固定値を設定する必要があります....それとも間違っていますか?