ravi wrote: > > d3<-merge(d1,d2,by.x=time1,by.y=time2) > will work only for exact matching. One possible option is to match > the times for the date and hour times only (by filtering away the > minute data). But this is only a partial solution as I am not > interested in data where the time difference is more than 15 minutes. > Why don't you, in the first "pass", round each time in d2 to a corresponding date in d1:
new.d2 <- d2 # there may be a faster solution without loops here for (i in 1:lenght(new.d2)) { # or whatever structure is d2 for (j in 1:length(d1)) { # again delta.t <- abs(new.dt2[i]$time2 - d1$time1) # get a vector of deltat's j.min <- which.min(delta.t) if (delta.t[j.min] <= 15 minutes) new.d2[i]$time1 <- d1[j.min]$time1 } } # and now merge them d3<-merge(d1, d2, by.x=time1, by.y=time1) Alberto Monteiro ______________________________________________ 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.