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 column?
--j On Tue, Jan 13, 2009 at 8:23 AM, Jeff Ryan <jeff.a.r...@gmail.com> wrote: > > The data.table package may be more in line with what you are after, but xts > and zoo can also do what you need in this particular example: > > > a <- xts(c('a1','a2','a3'), timeBasedSeq(20090101/20090103)) > > colnames(a) <- 'foo' > > > b <- xts(c('b1'), as.Date('2009-01-04')) > > colnames(b) <- 'foo' > > a > foo > 2009-01-01 "a1" > 2009-01-02 "a2" > 2009-01-03 "a3" > > b > foo > 2009-01-04 "b1" > > cbind(a,b) > foo foo.1 > 2009-01-01 "a1" NA > 2009-01-02 "a2" NA > 2009-01-03 "a3" NA > 2009-01-04 NA "b1" > > na.locf(cbind(a,b))['20090104'] > foo foo.1 > 2009-01-04 "a3" "b1" > > cbind/merge will merge along the union on the time-index by default (though > all common joins are supported). The subsetting by time will then find the > dates (or range of dates/times) that match. > > na.locf will carry forward last observations. That is from zoo; which > works > on xts, as xts extends zoo. > > HTH, > Jeff > > > > > mckenzig wrote: > > > > I have dataframe a: > > > > sym date val1 > > === ==== ==== > > foo 20090101 a1 > > foo 20090102 a2 > > foo 20090103 a3 > > > > and dataframe b: > > > > sym date val2 > > === ==== ==== > > foo 20090104 b1 > > > > I would like to join/merge them to generate the following: > > > > sym date val2 val1 > > === ==== ==== ==== > > foo 20090104 b1 a3 > > > > i.e. an equijoin on column 'sym' and a temporal join on column 'date' > > where the closest matching row is retrieved. I have been through the > > various regular/irregular timeseries packages and can not see anything > > like this. > > > > Regards. > > > > ______________________________________________ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > > > -- > View this message in context: > http://www.nabble.com/temporal-join-tp21395414p21437847.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.