| merge_df {sjmisc} | R Documentation |
Merges (full join) two (or more) data frames and preserve value and variable labels.
merge_df(x1, x2, ..., id = NULL)
x1 |
First data frame to be merged. |
x2 |
Second data frame to be merged. |
... |
More data frames to be merged. |
id |
Optional name for ID column that will be created to indicate the source data frames for appended rows. |
This function merges two data frames, where equal named columns
will be joined together. Matching rows are not omitted, hence all
rows from the data frames are preserved. This means that merge_df
row-binds all data frames, even if these have different numbers of
columns. Non-matching columns will be column-bound and filled with
NA-values for rows in those data frames that do not have
this column.
Value and variable labels are preserved. If matching columns have
different value label attributes, attributes from first data frame
will be used.
A full joined data frame.
library(dplyr) data(efc) x1 <- efc %>% select(1:5) %>% slice(1:10) x2 <- efc %>% select(3:7) %>% slice(11:20) mydf <- merge_df(x1, x2) mydf str(mydf) ## Not run: library(sjPlot) view_df(mydf) ## End(Not run) x3 <- efc %>% select(5:9) %>% slice(21:30) x4 <- efc %>% select(11:14) %>% slice(31:40) mydf <- merge_df(x1, x2, x3, x4, id = "subsets") mydf str(mydf)