Rにかなり慣れていないので、移動平均/ローリング平均について質問があります
Rで次のようなテーブルがあります:
CustomerID | ProductID | FiscalPeriod | Volume | GP
ABC123 987654 January 2013 $10,000 $3,000
ABC123 987654 February 2013 $500 $200
ABC123 987654 March 2013 $6,000 $2,000
XYZ555 123456 January 2013 $550 $150
XYZ555 123456 February 2013 $4,000 $800
...
各顧客/製品の組み合わせには、FiscalPeriod Volume/GP 値があります (ゼロであっても)。
最終的には、次のような出力が必要です。
CustomerID | ProductID | 3MthMovAvgVol| 12MthMovAvgVol| 3MthMovAvgGP | 12MthMovAvgGP
ABC123 987654 $7,500 $8,250 $1,750 $1,950
XYZ555 123456 $3,500 $4,650 $600 $800
目標は、顧客と製品の組み合わせごとに、ボリュームと GP の両方について 3 か月/12 か月の移動平均/ローリング平均を取得することです。
私はzooとttrを見てきましたが、これを実行する方法についてはどこにも行けないようです。
何か案は?