Saturday 6 January 2018

R Two (2) Data.Tables

Cited from R packages session 1 Arun Srinivasan

Suppose data.table's of A and B are keyed on colA and colB, and updating Acol (A specific column) by the product of Acol with Bcol (B specific column).
A[B, on = .(colA, colB), Acol := Acol * Bcol]

Suppose data.table's of A and B have common colA, and A specific column "valA" with B specific columns "begin" and "end". To update A specific column "valB" with NA.
Conditional operations
A[B, on = .(colA, valA > begin, valA < end), valB := NA]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
How to join (merge) data frames (inner, outer, left, right)?

No comments:

Post a Comment