replace_join | R Documentation |
full_join
with replacementPerform a modified dplyr::full_join()
on x
and y
,
returning all columns from x
,
non-matching rows from x
,
and all rows from y
.
Essentially replace_join()
replaces matching rows in x
with corresponding rows from y
and adds all unmatched rows from y
.
replace_join(
x,
y,
replace_col,
by = dplyr::intersect(names(x), names(y)) %>% dplyr::setdiff(replace_col),
copy = FALSE,
suffix = c(".x", ".y"),
...
)
x |
object on which replace_join will be performed.
|
y |
object on which replace_join will be performed.
|
replace_col |
the string name of the column (common to both |
by |
the string names of columns (common to |
copy |
passed to |
suffix |
appended to |
... |
passed to |
If x
contains multiple matching rows, matching rows in y
are inserted into x
at each matching location.
If y
contains multiple matching rows, all are inserted into x
at each matching location.
See examples.
Columns of x
and y
named in by
and replace_col
should not be factors.
If replace_col
is not in both x
and y
, x
is returned, unmodified.
a copy of x
in which matching by
rows are replaced by matched rows from y
and unmatched rows from y
are added to x
.
DFA <- data.frame(x = c(1, 2), y = c("A", "B"), stringsAsFactors = FALSE)
DFB <- data.frame(x = c(2, 3), y = c("C", "D"), stringsAsFactors = FALSE)
replace_join(DFA, DFB, replace_col = "y")
replace_join(DFB, DFA, replace_col = "y")
DFC <- data.frame(x = c(2, 2), y = c("M", "N"), stringsAsFactors = FALSE)
replace_join(DFA, DFC, replace_col = "y")
replace_join(DFC, DFA, replace_col = "y")
DFD <- data.frame(x = c(2, 2), y = c("A", "B"), stringsAsFactors = FALSE)
replace_join(DFC, DFD, replace_col = "y")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.