Here is a frequent problem i've come across recently in R with `data.table`

I have an index table, say DT1. The column x would be a subset of indexes. I would be working with a subtable of a bigger rawtable using these indexes. the subtable typically would be indexed from 1 to N. (thats the column y)

then for example, i would come across a table with pairs of indexes with the original indexing, and i want to know the corresponding new indexing.

Here's what it looks like

```
DT1 <- data.table(x=c(0,3,5),y= c(11,22,33))
DT2 <- data.table(x=c(3,3,0,0,5),x=c(0,5,0,3,5))
# > DT1
#    x y
# 1: 0 11
# 2: 3 22
# 3: 5 33

# > DT2
#    x x
# 1: 3 0
# 2: 3 5
# 3: 0 0
# 4: 0 3
# 5: 5 5

```

Here is a tortuous way i found

```
cbind(DT1[DT2[,1,with=FALSE],on="x"][,2,with=FALSE],DT1[DT2[,2,with=FALSE],on="x"][,2,with=FALSE])
#     y  y
# 1: 22 11
# 2: 22 33
# 3: 11 11
# 4: 11 22
# 5: 33 33

```

a more basic way to do this with `sapply` gives the same result

```
tab=DT1$x
lookup <- function(value){DT1$y[which(tab==value)]}

colnames(DT2) <- c("x","xx")

ans <- as.data.table(cbind(sapply(DT2$x,lookup),sapply(DT2$xx,lookup)))
colnames(ans) <- c("y","y")

```

However, 
the first solution looks a bit ugly to me

I don't like the second one, because I need to define assign a value to tab each time i use the function lookup in `lapply`.
if I had to lookup in different tables, i would have the choice either to create a new lookup function specific to that table, or to store in memory in a (temp) variable tab.
perhaps there is a way to do the `lapply` with a function of two variables
 `lookup <-function (tab,value) {...}` ? that i don't know

I'm sure there are many other ways.
I'm not sure what i'm doing exactly with the first solution. basically the syntax in `data.table` has to do with (inner and outer) JOINS. but in the final output, i want to keep the original order of the table DT2. setting column x as a key for DT2 would sort that column, making stuff like `merge` being not adapted to that ?

I'm willing to hear from you what is the best implementation, - i'm sure there are many better ones - and also , the most efficient when dealing with very very large tables.