Your data appear to be monthly, so I would strongly recommend you move from a POSIXct
index to a Date
or yearmon
index. Otherwise you may run into issues with timezones and daylight saving time.
One way to solve this problem is to merge xts.1
and xts.2
, then loop over all the rows of the resulting object, subsetting the column by the xts.2
column in the merged data.
Since your data are monthly, you can loop over all the observations with apply.monthly
.
> xts.3 <- merge(xts.1,xts.2)
> apply.monthly(xts.3, function(x) x[,x$xts.2])
[,1]
2003-07-30 17:00:00 0.20151730
2003-08-28 17:00:00 0.04631253
2003-09-29 17:00:00 0.08023267
2003-10-30 16:00:00 0.11427968