For example, I have two ZOO objects:

x <- zoo(matrix(1:10, 10, 2), 1:10)
y <- zoo(matrix(11:20, 10, 2), 5:15)

I want to get first index value, which have both ZOO objects. In this example it must be index value of 5. Because index of 5 have both objects and this is most recent index.

I can loop index(x) vector and with inner loop compare every index(y) element with index(x) elements, but this looks ugly. Can i do that without looping? Thanks.

UPDATE: I found that I can do following:

idx_val <- head(intersect(index(x), index(y)), 1)

This is clear and fast solution? If yes, then question is closed.

有帮助吗?

解决方案

Have transferred this from comment to here and improved slightly. This approach differs from the one posted in the question in the case that there are leading NA values in x or y :

start(na.omit(merge(x, y)))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top