View source: R/utils_join_coalesce.R
join_coalesce | R Documentation |
EXPERIMENTAL! This function joins two dataframes together by key, and then coalesces any columns that have shared names (i.e. fills in NAs). A utility function primarily used internally within nflverse to help build player IDs
join_coalesce(
x,
y,
by = NULL,
type = c("left", "inner", "full"),
...,
by.x = NULL,
by.y = NULL,
sort = TRUE,
incomparables = c(NA, NaN)
)
x , y |
dataframes. Will be coerced to data.table |
by |
keys to join on, as a plain or named character vector |
type |
one of "left" (all rows of x and matching rows of y), "inner" (matching rows of x and y), "full" (all rows of x and y) |
... |
other args passed to |
by.x , by.y |
alternate form of keys to join on - if provided, will override |
sort |
whether to sort output by the join keys |
incomparables |
keys to NOT match on, i.e. NA should not match on NA. |
a data.frame joining x and y dataframes together, with every column from both x and y and patching NA values in x with those in y.
x <- data.frame(id1 = c(NA_character_,letters[1:4]), a = c(1,NA,3,NA,5), b = 1:5 * 10)
y <- data.frame(id2 = c(letters[3:11],NA_character_), a = -(1:10), c = 1:10 * 100)
join_coalesce(x,y, by = c("id1"="id2"))
join_coalesce(x,y, by.x = "id1", by.y = "id2")
join_coalesce(x,y, by = c("id1"="id2"), type = "inner")
join_coalesce(x,y, by = c("id1"="id2"), type = "full")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.