mergeByRef: Merge two tables by reference

Description Usage Arguments Value Examples

View source: R/mergeByRef.R

Description

This function can be used when one wants to get exactly the same table but with some new columns got from a another table. Technically this is equivalent to a left join without row duplication. Unlike with the default merge function, mergeByRef() does not copy data; it modifies it by reference. This results in a great performance improvement.

Usage

1
2
mergeByRef(x, y, by = intersect(names(x), names(y)),
  colsToAdd = setdiff(names(y), by))

Arguments

x

data.table or object inheriting from data.table.

y

data.table or object inheriting from data.table.

by

Name of columns used for merging. By default, the function uses all common columns.

colsToAdd

Name of columns of y to add to x. By default the function adds all columns of y that are not in x.

Value

mergeByRef() modifies its first input by reference so it is used for its side effects. Nevertheless for convenience it invisibly returns x with the new columns appended

Examples

1
2
3
4
5
6
7
8
require(data.table)

x <- data.table(a = 1:5, b = rnorm(5))
y <- data.table(a = 1:5, c = rnorm(5))

# Add the "c" column from y to x
mergeByRef(x, y)
names(x)

rte-antares-rpackage/antaresDev documentation built on May 17, 2019, 5:53 p.m.