[R] temporal join

Gabor Grothendieck ggrothendieck at gmail.com
Sat Mar 14 11:03:30 CET 2009

zoo makes no assumptions regarding times and
dates other than they are ordered and have certain
methods. It doesn't even know the difference between
a time and a date nor does it know about any time
or date classes.  (The exception is interface routines
such as read.zoo.)

If the dates uniquely specify the date times do we really
need the times in the first place and if we have them
what times would the merged object have?  The easiest
solution seems to be just convert to dates only.  Thus
assuming the dates uniquely specify the points:

On Fri, Mar 13, 2009 at 10:12 PM, Jonathan Greenberg <jgrn307 at gmail.com> wrote:
> Jeff:
> As a followup to this question -- I have a pair of tables that I want to do
> a 1 to 1 join on, but the date field contains the full time, down to the
> second, to base the join on (e.g. in a given day, there are going to MANY
> observations, but not at the exact same time).  I might be missing
> something, but it appears that zoo (and xts) work on dates, rather than
> dates+times?  If so, how do I join a date/time column to another date/time

At least for zoo that's not true. It has no idea of what the index class is.
All it knows is that its some ordered class that has certain methods.
(The exception is interface routines as they need to may external

> column?

If its truly 1-1, i.e. they have the same number of comonents and
the i-th component of the first series corresponds to the i-th
component of the second seriesm, then just cbind their data and
use the times of the first series, say:


# test data
x <- zoo(1:3, as.chron("2000-01-01 18:12:00") + 0:2)
y <- zoo(4:6, time(x) + 0.1)

zoo(cbind(coredata(x), coredata(y)), time(x))

More information about the R-help mailing list