1. 学ぶ
  2. /
  3. コース
  4. /
  5. Rで学ぶ時系列データ操作

Connected

演習

直前値の保持(LOCF)

もう一つ重要な補完手法が「Last observation carried forward(LOCF)」です。この方法は、欠損値をその直前に現れた NA ではない最新の値で埋めることで機能します。

この演習では、学生の月次試験スコアの時系列 monthly_test_scores を補完します。データセットと、ggplot2 と zoo パッケージはあらかじめ利用可能です。

指示

100 XP
  • last observation carried forward を用いて monthly_test_scores の欠損値を補完し、monthly_scores_locf として保存します。

  • 最初の autoplot() を完成させ、元の monthly_test_scores の時系列プロットを作成します。

  • monthly_scores_locf を 'minimal' テーマで自動プロットし、y 軸ラベルを "Examination Score (LOCF)" にします。

  • プロット間を切り替えて、monthly_scores_locf のプロットと monthly_test_scores のプロットを比較します。