Re: [R] fuzzy merge

From: Alberto Monteiro <albmont_at_centroin.com.br>
Date: Wed, 09 Apr 2008 10:48:07 -0200

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_at_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. Received on Wed 09 Apr 2008 - 12:51:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 Apr 2008 - 13:30:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive