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.
Este exercício faz parte do curso
Importing and Managing Financial Data in R
Instruções do exercício
- Use the
merge()
function to combineirregular_xts
andregular_xts
into an object namedmerged_xts
. - Use
head()
to look at the first few rows ofmerged_xts
. - Create an object named
merged_filled_xts
by using thefill
argument tomerge()
to replace theNA
with the last observation, carried forward (na.locf
). - Use
head
to look at the first few rows ofmerged_filled_xts
.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# 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