
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.
meld(
...,
by = NULL,
all = TRUE,
no.dups = FALSE,
csv = FALSE,
rdata = FALSE,
spss = FALSE
)
A merged data frame based on the specified or common candidate keys.
Clean data frames to be merged.
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.
Logical; if TRUE, performs an OUTER JOIN. If FALSE, performs an INNER JOIN.
Logical; if TRUE, duplicates are removed post-merge.
Logical; if TRUE, the merged data frame is exported as a CSV file.
Logical; if TRUE, the merged data frame is saved as an Rda file.
Logical; if TRUE, the merged data frame is exported as an SPSS file.
Joshua Kenney joshua.kenney@yale.edu
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