add_cols: Adds cols from data.table SOURCE to data.table TARGET

Description Usage Arguments Examples

View source: R/add_cols.R

Description

Only done when there if rows are uniquely identified by on Returns TARGET invisibly

Usage

1
add_cols(TARGET, SOURCE, on, cols)

Arguments

TARGET

Target data.table

SOURCE

Source data.table

on

Which variables to join on. When unequal for TARGET and SOURCE, must be named vector, where the names correspond to the SOURCE.

cols

Which cols to add

Examples

1
2
3
4
5
6
7
8
9
TARGET = data.table(id = rep(1:10, each = 3))
SOURCE = data.table(id = 1:5)[, x := rnorm(.N)][, y := rnorm(.N)]
add_cols(TARGET, SOURCE, on = "id", cols = c("x", "y"))
TARGET[]
# Case of unequal named join vars
X = data.table(id0 = 1:10)
Y = data.table(id1 = 3:5)[, z := c("a", "b", "c")]
add_cols(X, Y, on = c("id1" = "id0"), cols = "z")
X[]

matthiaskaeding/matthiastools documentation built on Feb. 22, 2022, 5:09 p.m.