Initializing playground…
← Back to roadmap

merge_asof (ordered nearest-key join)

mergeAsof is an ordered left-join that matches on the nearest key rather than an exact key. It is especially useful for time-series data — e.g., matching each trade to the most recent quote.

Basic example — backward (default)

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

Forward direction

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

Nearest direction

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

Grouping with by

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

Tolerance

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

Different key column names (left_on / right_on)

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

Using index as key

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent