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

Bert Gunter <[email protected]> Thu, 23 Jul 2026 11:10:22 -0700
Newsgroups gmane.comp.lang.r.general
Message-ID <CAGxFJbR5AMLeH2oQNEYaezcOCHU1A9j7t5mvCyAf=oP9SaCmYA@mail.gmail.com>
... and related to Ravi's post, will there always be at least one date in
file 2 that matches every date in file 1?  And if there isn't, what action
should be taken?

-- Bert

On Thu, Jul 23, 2026 at 9:36=E2=80=AFAM Ravi Varadhan via R-help <
[email protected]> wrote:

> 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 functi=
on
> in the clue package) to find the combination of matches that results in t=
he
> lowest total date difference across the entire dataset.
>
> Ravi
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [email protected] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> https://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]