1. Learn
  2. /
  3. Courses
  4. /
  5. Importing and Managing Financial Data in R

Connected

Exercise

Use merge to make an irregular index regular

The previous exercise taught you how to make a zero-width xts object with a regular time index. You can use the zero-width object to regularize an irregular xts object.

The regularized series usually has missing values (NA) because the irregular data does not have a value for all observations in the regular index. This exercise will teach you how to handle these missing values when you merge() the two series.

The irregular_xts and regular_xts objects from the previous exercise are available in your workspace.

Instructions

100 XP
  • Use the merge() function to combine irregular_xts and regular_xts into an object named merged_xts.
  • Use head() to look at the first few rows of merged_xts.
  • Create an object named merged_filled_xts by using the fill argument to merge() to replace the NA with the last observation, carried forward (na.locf).
  • Use head to look at the first few rows of merged_filled_xts.