add_rows: Merge labelled data frames

Description Usage Arguments Details Value Examples

View source: R/merge_df.R

Description

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

Usage

1
2
3
add_rows(..., id = NULL)

merge_df(..., id = NULL)

Arguments

...

Two or 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.

Details

This function works like dplyr::bind_rows(), but preserves variable and value label attributes. add_rows() row-binds all data frames in ..., 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.

merge_df() is an alias for add_rows().

Value

A full joined data frame.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
library(dplyr)
data(efc)
x1 <- efc %>% select(1:5) %>% slice(1:10)
x2 <- efc %>% select(3:7) %>% slice(11:20)

mydf <- add_rows(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 <- add_rows(x1, x2, x3, x4, id = "subsets")
mydf
str(mydf)

sjmisc documentation built on Jan. 10, 2020, 9:07 a.m.