I have the following scenario, I first create a data table as shown below
x = data.table(f1 = c('a','b','c','d'))
x = x[,rn := .I]
This yields
> x
f1 rn
1: a 1
2: b 2
3: c 3
4: d 4
>
Where rn is simply the row number. Now, I have another data.table y as
y = data.table(f2=c('b','c','f'))
What I would like to be able to do is for elements in y that are in x, I want to subtract 2 from the corresponding values in rn. So the expected data.table is
x
f1 rn
1: a 1
2: b 0
3: c 1
4: d 4
How does one get to this? x[y]
and y[x]
don't help at all as they just do joins.