I have two reference tables ,ref1
and ref2
. and a dataset, df
. All are data.tables
ref1
has variables "V1"
, "V2"
and "x"
ref2
has variables "V1"
and "x"
df
has variables "V1"
and "V2"
I want to extract the values of "x"
from ref1
and ref2
based on the appropriate values for "V1"
and "V2"
. There is no overlap between "V1"
values in ref1
and ref2
.
Some MWE data:
ref1 <- data.table(
V1 = c("a","a","a","b","b","b","e","e"),
V2 = c("1","2","3","4","5","6","10","11"),
x = c(43,66,12,19,92,30,44,56)
)
ref2 <- data.table(
V1 = c("c","d"),
x = c(100,200)
)
df <- data.table(
V1 = c("a","b","c","d","f"),
V2 = c("2","4","7","9","14")
)
target <- data.table(
V1 = c("a","b","c","d","f"),
V2 = c("2","4","7","9","14"),
x = c(66,19,100,200,NA)
)