nonequimerge: Merge two tables using non-equi (inequality) conditions

View source: R/nonequimerge.R

nonequimergeR Documentation

Merge two tables using non-equi (inequality) conditions

Description

Unlike a plain equi-merge, nonequimerge() supports inequality conditions between columns of x and y (for example, matching each x row to every y row whose date range contains x's date), in addition to any exact-match columns in by.

Usage

nonequimerge(x, y, by, ...)

Arguments

x, y

Data frames or data tables to join.

by

Character vector of join conditions. A plain column name (present in both x and y) is matched exactly; an entry containing a comparison operator, written as "xcol<op>ycol" (e.g. "date>=start_date", "date<=end_date"), is matched as an inequality between x's xcol and y's ycol. This uses "col>=other" style comparison strings.

...

Currently ignored; reserved for future join (e.g. mult, roll).

Value

A basetable with one row per matching x/y pair (an inner join: rows of x with no matching y row are dropped).

Examples

x <- data.frame(id = 1, date = as.Date("2024-01-15"))
y <- data.frame(
  id = 1,
  start_date = as.Date(c("2024-01-01", "2024-02-01")),
  end_date = as.Date(c("2024-01-31", "2024-02-28")),
  period = c("Jan", "Feb")
)
nonequimerge(x, y, by = c("id", "date>=start_date", "date<=end_date"))

basetable documentation built on Sept. 18, 2026, 9:13 a.m.