문제

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