I have the following xts object and data frame in R.
xts:
data frame:
I need to join them by date, the date in the xts object being one workday forward the date in the data frame, for each record that needs to be matched.
So I would need to find what is the closest day forward in the xts object so to join the data from the data frame.
Desired result (xts object):
CodePudding user response:
The way I solved this was to lag the 'date' column from the xts object, then added it as a new column to a data frame object. After that I joined the data frames as usual.
lag_dates <- lag(index(returns))
returns <- cbind(data.frame(returns), lag_dates = as.Date(lag_dates))