merge_data_tables {exploratory} | R Documentation |
Merge data tables
Description
Merge two data.table objects. If there are any duplicated ID values and column names across the two data tables, the cell values in the first data.table will remain intact and the cell values in the second data.table will be discarded for the resulting merged data table.
Usage
merge_data_tables(dt1 = NULL, dt2 = NULL, id = NULL, silent = TRUE)
Arguments
dt1 |
the first data.table which will remain intact |
dt2 |
the second data.table which will be joined outside of (around) the first data.table. If there are any duplicated ID values and column names across the two data tables, the cell values in the first data.table will remain intact and the cell values in the second data.table will be discarded for the resulting merged data table. |
id |
name of the column that will contain the ID values in the two data tables. The name of the ID column must be identical in the two data tables. |
silent |
If |
Value
a data.table object, which merges (joins) the second data.table around the first data.table.
Examples
data_1 <- data.table::data.table(
id_col = c(4, 2, 1, 3),
a = 3:6,
b = 5:8,
c = c("w", "x", "y", "z"))
data_2 <- data.table::data.table(
id_col = c(1, 4, 99),
d = 6:8,
b = c("p", "q", "r"),
e = c(TRUE, FALSE, FALSE))
merge_data_tables(dt1 = data_1, dt2 = data_2, id = "id_col")