I have a data.table
called big
in which I want to replace all corresponding values from data.table
called new_big
.
library(data.table)
big <- structure(list(id = c("B", "C", "D", "E", "F", "G", "H", "I",
"J", "K"), col = c(103L, 103L, 102L, 105L, 104L, 103L, 104L, 104L,
104L, 103L)), row.names = c(NA, -10L), class = c("data.table",
"data.frame"))
new_big <- structure(list(id = c("B", "E", "G"), col = c(1, 11, 111)), row.names = c(NA,
-3L), class = c("data.table", "data.frame"))
They create:
> big
id col
1: B 103
2: C 103
3: D 102
4: E 105
5: F 104
6: G 103
7: H 104
8: I 104
9: J 104
10: K 103
> new_big
id col
1: B 1
2: E 11
3: G 111
Here is the desired output -
id col
1: B 1
2: C 103
3: D 102
4: E 11
5: F 104
6: G 111
7: H 104
8: I 104
9: J 104
10: K 103
Is there a way to join these two tables to get the desired output?
I tried following but I could not get the desired output as shown above. Any pointers will be helpful.
big[new_big, on = .(id)]
id col i.col
1: B 105 1
2: E 103 11
3: G 101 111