Get startedGet started for free

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.

This exercise is part of the course

Importing and Managing Financial Data in R

View Course

Exercise instructions

  • 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.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Merge irregular_xts and regular_xts


# Look at the first few rows of merged_xts


# Use the fill argument to fill NA with their previous value


# Look at the first few rows of merged_filled_xts
Edit and Run Code