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.
Cet exercice fait partie du cours
Importing and Managing Financial Data in R
Instructions
- Use the
merge()function to combineirregular_xtsandregular_xtsinto an object namedmerged_xts. - Use
head()to look at the first few rows ofmerged_xts. - Create an object named
merged_filled_xtsby using thefillargument tomerge()to replace theNAwith the last observation, carried forward (na.locf). - Use
headto look at the first few rows ofmerged_filled_xts.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de 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