Skip to content

Instantly share code, notes, and snippets.

@xiesixia
xiesixia / coalesce_join.R
Last active August 22, 2024 13:32
Coalesce join function applied to data frame (expand coalesce function from dplyr)
# For detailed explaination of this function, check this blog post: https://asterhu.com/post/2023-05-11-coalesce-join-in-r/
# Reference: https://alistaire.rbind.io/blog/coalescing-joins/
require(dplyr)
require(stringr)
coalesce_join <- function(x, y,
by = NULL,
keep = c("left", "right"), # "left" means keep value from left table if there's any duplicate value in both tables.
suffix = c(".x", ".y"),
join = c("full_join","left_join", "right_join", "inner_join")) {