Skip to content
Prev 5201 / 15274 Next

row-by-row operations on multiple xts matrices

Folks,
 
If I have two xts objects with some dates in common, and I want to
compute, say, the sum of products of their corresponding rows,
what is a good way of achieving it?
Were these matrices, I could just do something like (inefficiently):
but that doesn't work here, because the transpose t() function removes
the xts-ness of b, and the multiplication occurs row-by-row
without date correspondence.
 
Is there a better way to achieve this than:
 
# First extract common indices
# Then use the common index to construct a new xts object
[,1]
1970-01-03  134
1970-01-04  172
1970-01-05  214
1970-01-06  260

I think there's something obvious I'm missing... 

Thanks,
 
Murali