50% off: Unlimited data and AI learning.
State of Data and AI Literacy Report 2025

wizaRdry (version 0.2.6)

meld: Merge two or more data frames magically according to their candidate key

Description

This function simplifies the process of merging multiple cleaned data frames by automatically determining common merge keys or utilizing user-specified keys. Supports both inner and outer join methods, and offers options for exporting the merged data.

Usage

meld(
  ...,
  by = NULL,
  all = TRUE,
  no.dups = FALSE,
  csv = FALSE,
  rdata = FALSE,
  spss = FALSE
)

Value

A merged data frame based on the specified or common candidate keys.

Arguments

...

Clean data frames to be merged.

by

A vector of strings specifying the column names to be used as merge keys. If NULL, the function automatically determines common keys from the provided data frames.

all

Logical; if TRUE, performs an OUTER JOIN. If FALSE, performs an INNER JOIN.

no.dups

Logical; if TRUE, duplicates are removed post-merge.

csv

Logical; if TRUE, the merged data frame is exported as a CSV file.

rdata

Logical; if TRUE, the merged data frame is saved as an Rda file.

spss

Logical; if TRUE, the merged data frame is exported as an SPSS file.

Author

Joshua Kenney joshua.kenney@yale.edu

Examples

Run this code
if (FALSE) {
# Create sample dataframes for demonstration
df1 <- data.frame(
  src_subject_id = c("S001", "S002", "S003"),
  visit = c(1, 2, 1),
  measure1 = c(10, 15, 12),
  stringsAsFactors = FALSE
)

df2 <- data.frame(
  src_subject_id = c("S001", "S002", "S004"),
  visit = c(1, 2, 2),
  measure2 = c(85, 92, 78),
  stringsAsFactors = FALSE
)

# Perform an OUTER JOIN using default keys:
merged1 <- meld(df1, df2, all = TRUE)

# Perform an INNER JOIN using specified keys:
merged2 <- meld(df1, df2, by = "src_subject_id", all = FALSE)
}

Run the code above in your browser using DataLab