I am building a time series (xts) from several observations stored in a list of xts objects. The extracted data is missing sometimes, R report the error:
"Error in NextMethod(.Generic) : replacement has length zero"
I would like R to report NA instead. I guess the answer lies in tryCatch(), but I'm unable to nail it.
# Here is a MCVE:
Contract <- list(xts(1:12,order.by=Sys.Date()-1:12),
xts(1:10,order.by=Sys.Date()-1:10),
xts(1:8,order.by=Sys.Date()-2:9))
Vol <- xts(matrix(0, 12,3, byrow = FALSE),order.by=Sys.Date()-1:12)
for (A in 1:12){for (B in 1:3){
Vol[A,B] <- Contract[[B]][index(Vol)[A]]
}}
Vol
Any help would be gladly appreciated. (Also, if someone as clever idea to vectorize the double loop...)