Question: I have collection in which consist of large amount of **Hetrogenous Objects**. e.g.

```
    Employee e1, e2, e3 = new Employee();
    Student s1, s2, s3 = new Student();
    Department d1, d2, d3 = new Department(); 
........etc 

```

I need to traverse this collection and all similar objects needs to grouped together and put in another new collection. Means `e1, e2, e3` we can put in one collection.
We can use `InstanceOf`, but that will good if there are only 2-3 types of object.
What will generic solution for this.

Answer: 
We can try with `data.table`. It should be very fast as we are assigning (`:=`) in place. Convert the 'data.frame' to 'data.table' (`setDT(t1)`), join with 't2' `on` 'x1' and 'x2', then assign 'i.x3' values to 'x3'. 

```
library(data.table)
setDT(t1)[t2, x3 := i.x3, on = c("x1", "x2")]
t1
#   x1 x2 x3
#1:  1  I  a
#2:  7  R  a
#3:  3  R  a
#4:  4  I  b
#5:  2  I  b
#6:  6  R  b

```

---

Or we can use `match`

```
t1$x3 <- factor(t1$x3, levels = c('a','b'))
t1[match(do.call(paste,t2[-3]), do.call(paste, t1[-3])), 'x3'] <- t2$x3
t1
# x1 x2 x3
#1  1  I  a
#2  7  R  a
#3  3  R  a
#4  4  I  b
#5  2  I  b
#6  6  R  b

```
I think this would give what you want. 

Convert `x3` column to character in `t1` and `t2`and then check the condition

```
t1$x3 <- as.character(t1$x3)
t2$x3 <- as.character(t2$x3)
t1[t1$x1 %in% t2$x1 & as.character(t1$x2) %in% as.character(t2$x2), "x3"] <- t2$x3

> t1
#  x1 x2 x3
#1  1  I  a
#2  7  R  a
#3  3  R  a
#4  4  I  b
#5  2  I  b
#6  6  R  b

```