Get startedGet started for free

Aggregate daily data and merge with monthly data

Sometimes two series have the same periodicity, but represent timestamps differently. For example, monthly series may be timestamped with the first or last date of the month. This difference creates many NA when series are merged. The yearmon class from the zoo package helps solve this problem.

In this exercise, you will aggregate the FRED daily Fed Funds rate (DFF) to a monthly periodicity and merge it with the FRED monthly Fed Funds rate (FEDFUNDS).The DFF aggregate will be timestamped with the last day of the month, while FEDFUNDS is timestamped with the first day of the month.

The FEDFUNDS and DFF data have already been downloaded from FRED for you, using getSymbols(c("FEDFUNDS", "DFF"), src = "FRED").

This exercise is part of the course

Importing and Managing Financial Data in R

View Course

Exercise instructions

  • Use apply.monthly() with mean() to calculate the average of all days for each month. Assign the result to monthly_fedfunds.
  • Finish the command to use as.yearmon() to convert the index to yearmon.
  • Create an object named merged_fedfunds by merging FEDFUNDS with the monthly aggregate you created in the first step.
  • Use head() to check the output of merged_fedfunds.

Hands-on interactive exercise

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

# Aggregate DFF to monthly averages


# Convert index to yearmon
index(___) <- ___(index(___))


# Merge FEDFUNDS with the monthly aggregate


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