Learn R Programming

sjmisc (version 1.7)

merge_df: Merge labelled data frames

Description

Merges (full join) two data frames and preserve value and variable labels.

Usage

merge_df(x1, x2, id = NULL)

Arguments

x1
First data frame to be merged.
x2
Second data frame to be merged.
id
Optional name for ID column that will be created to indicate the source data frames for appended rows.

Value

  • A full joined data frame.

Details

This function merges two data frames, where equal named columns will be joined together. This function is a convenient wrapper for merge(x1, x2, all = TRUE), however, unlike base merge, this function preserves value and variable labels. If matching columns have different value label attributes, attributes from first data frame will be used. For more details on the join operation, see 'Details' in merge on all-argument.

Examples

Run this code
library(dplyr)
data(efc)
x1 <- efc %>% select(1:5) %>% slice(1:10)
x2 <- efc %>% select(3:7) %>% slice(1:10)

mydf <- merge_df(x1, x2)
mydf
str(mydf)

library(sjPlot)
view_df(mydf)

Run the code above in your browser using DataLab