I have two data tables like this:
df1 <- data.table(ID = 1:10,
                  text = c("a", NA, NA, "b", NA, "a", "a", NA, "c", NA))
df2 <- data.table(ID = c(2,3,8),
                  text = c("a", "b", "a"))
I would like to fill the text column in df1 with the values from df2 based on the ID. Notice that not each ID has a value in the text column in df1 or in df2.
I would like my result to look like this:
    ID text
 1:  1    a
 2:  2    a
 3:  3    b
 4:  4    b
 5:  5 <NA>
 6:  6    a
 7:  7    a
 8:  8    a
 9:  9    c
10: 10 <NA>
When possible, the values should be taken from df2, otherwise the column text in df1 should remain empty.
I would really appreciate your help!
 
     
     
    