In R, I have two data frames that contain list columns
d1 <- data.table(
group_id1=1:4
)
d1$Cat_grouped <- list(letters[1:2],letters[3:2],letters[3:6],letters[11:12] )
and
d_grouped <- data.table(
group_id2=1:4
)
d_grouped$Cat_grouped <- list(letters[1:5],letters[6:10],letters[1:2],letters[1] )
I would like to combine these two data.tables based on vectors in d1$Cat_groupedcontained in vectors ind_grouped$Cat_grouped
To be more precise, there can be two matching criteria:
a) all elements of each vector d1$Cat_groupedmust be in a consistent vectord_grouped$Cat_grouped
The result is the following match:
result_a <- data.table(
group_id1=c(1,2)
group_id2=c(1,1)
)
b) at least one of the elements in each vector d1$Cat_groupedmust be in a consistent vectord_grouped$Cat_grouped
The result is the following match:
result_b <- data.table(
group_id1=c(1,2,3,3),
group_id2=c(1,1,1,2)
)
How can I implement a) or b)? Preferably in the form of a data table.
EDIT1: Expected Results a) and b) added
EDIT2: d_grouped, .