Re: Matching where the source file has one record/ subject and the to-be-matched file has multiple records/subect

Ravi Varadhan via R-help <[email protected]> Thu, 23 Jul 2026 15:01:29 +0000
Newsgroups gmane.comp.lang.r.general
Message-ID <DS4PR01MB9434471A8AC7D6257988C9BEF2C02@DS4PR01MB9434.prod.exchangelabs.com>
This is a classic matching problem, I believe.  Based on your description, you are looking for a 1-to-1 nearest-neighbor match based on the absolute difference in dates, with the constraint that once a subject in File 2 is used, all of their records are discarded.

Correct?

There are two classical approaches: greedy matching and global optimal matching.  While the greedy approach is simple to implement and often works, it can sometimes get into trouble (i.e., run out of good matches). The optimal approach would use the Hungarian algorithm (e.g., LSAP function in the clue package) to find the combination of matches that results in the lowest total date difference across the entire dataset.

Ravi

	[[alternative HTML version deleted]]