merge_duplicate: Merge Data Frames Handling Duplicated Column Names

View source: R/merge_duplicate.R

merge_duplicateR Documentation

Merge Data Frames Handling Duplicated Column Names

Description

This function merges two data frames by resolving duplicated column names based on user preference. It provides options to choose which data frame's duplicated columns to keep, ensuring smooth merges without losing important data integrity.

Usage

merge_duplicate(x, y, by.x, by.y, all.x, all.y, all = NULL, choose = "x")

Arguments

x

The first data frame to be merged.

y

The second data frame to be merged.

by.x

The column name(s) in 'x' used for merging.

by.y

The column name(s) in 'y' used for merging.

all.x

Logical indicating if all rows from 'x' should be included in the output.

all.y

Logical indicating if all rows from 'y' should be included in the output.

all

Logical indicating if all rows from both 'x' and 'y' should be included in the output, superseding 'all.x' and 'all.y' if not NULL.

choose

Specifies which data frame's duplicated non-joining columns should be retained: "x" or "y".

Value

A data frame resulting from merging 'x' and 'y' according to the specified parameters.

Examples

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)
merged_df <- merge_duplicate(df1, df2, by.x = "ID", by.y = "ID", all.x = TRUE, all.y = FALSE, choose = "x")

IOBR/IOBR documentation built on Sept. 9, 2024, 8:36 p.m.