View source: R/merge_duplicate.R
| merge_duplicate | R Documentation |
Merges two data frames, resolving duplicated column names according to user preference. Allows selection of which data frame's duplicated columns to retain, ensuring data integrity during merging.
merge_duplicate(
x,
y,
by.x,
by.y,
all.x = FALSE,
all.y = FALSE,
all = NULL,
choose = c("x", "y")
)
x |
Data frame. First data frame to merge. |
y |
Data frame. Second data frame to merge. |
by.x |
Character. Column name(s) in 'x' used for merging. |
by.y |
Character. Column name(s) in 'y' used for merging. |
all.x |
Logical. Include all rows from 'x' in output. Default is 'FALSE'. |
all.y |
Logical. Include all rows from 'y' in output. Default is 'FALSE'. |
all |
Logical or 'NULL'. If not 'NULL', include all rows from both 'x' and 'y', overriding 'all.x' and 'all.y'. |
choose |
Character. Which data frame's duplicated non-joining columns to retain: '"x"' or '"y"'. Default is '"x"'. |
Data frame resulting from merging 'x' and 'y' according to specified parameters.
df1 <- data.frame(ID = 1:3, Name = c("A", "B", "C"), Value = 1:3)
df2 <- data.frame(ID = 1:3, Name = c("X", "Y", "Z"), Score = 4:6)
# Merge keeping duplicated columns from x
merged_df <- merge_duplicate(df1, df2,
by.x = "ID", by.y = "ID",
all.x = TRUE, choose = "x"
)
print(merged_df)
# Merge keeping duplicated columns from y
merged_df2 <- merge_duplicate(df1, df2,
by.x = "ID", by.y = "ID",
all = TRUE, choose = "y"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.