mergeData: Merge Many Data Frames, Check For Inconsistencies, and...

View source: R/mergeData.R

mergeDataR Documentation

Merge Many Data Frames, Check For Inconsistencies, and Replace NA Values

Description

This function merges a list of data frames. Further, it provides detailed diagnostics about value mismatches. If two identically named columns in two datasets do not have identical values, NAs are replaced by valid codes stemming from the other dataset(s) and if two different valid values are found, the first value will be kept and the other dropped, and the user will be informed about the mismatch. Additionally, NA resulting from the merge (e.g., in repeated block designs) can be replaced with a customed character missing to facilitate future data preparation of the merged dataset. See collapseMissings for details on supported character missings for other functions in the eatPrep package.

Usage

mergeData(newID, datList, oldIDs = NULL, addMbd = FALSE,
                  overwriteMbdSilently=TRUE, verbose = TRUE)

Arguments

newID

A character vector of length 1 indicating the name of the identifier variable (ID) in the merged dataset and/or the name of the ID in every data.frame in datList, if not specified differently in oldIDs.

datList

A list of data frames to be merged

oldIDs

A character vector or a numeric vector containing either the names of the identifier variables in datList or their column number in each data frame in datList. Default is a vector containing length(datList) replicates of the value of newID.

addMbd

logical. If TRUE, NA is replaced by "mbd" (missing by design) in the merged dataset.

overwriteMbdSilently

Logical. Whether mbd will overwritten silently when other non-empty values are available.

verbose

logical. If TRUE, progress is printed.

Value

A data frame containing unique cases and unique variables. All cases and all variables from the original datasets will be kept and matched.

Author(s)

Karoline Sachse

Examples

data(inputDat)
str(inputDat)

mergedDataset <- mergeData("idstud", inputDat, c("ID", "ID", "ID"), addMbd=TRUE)
str(mergedDataset)

mergedDataset <- mergeData("ID", inputDat, verbose=TRUE)
str(mergedDataset)

sachseka/eatPrep documentation built on June 9, 2025, 9:36 a.m.