1

Say I have two dataframes:

a <- data.frame(id = 1:5, nom = c("a", "b", "c", "d", "e"))
b <- data.frame(id = 3:1, nom = c("C", "B", "A"))

and i would like to join the two dataframes such that it still has two columns (id and nom) but where id = 4 and id = 5 the nom column retains the d and e values respectively. How do I achieve this? the solution I'd like looks like this:

enter image description here

Essentially, I'd like to avoid the NA output and retain the old rows where a left join match does not exist.

  • Thanks for adding output. From the link, you can do: `library(data.table); setDT(a); setDT(b); a[b, on=.(id), nom := i.nom][]`. I'll see if I can find other relevant links. – Frank Aug 23 '18 at 15:13

0 Answers0